
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.analysis.chemenv.coordination_environments.structure_environments &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../../" src="../../../../../_static/documentation_options.js"></script>
    <script src="../../../../../_static/jquery.js"></script>
    <script src="../../../../../_static/underscore.js"></script>
    <script src="../../../../../_static/doctools.js"></script>
    <script src="../../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.chemenv.coordination_environments.structure_environments</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.analysis.chemenv.coordination_environments.structure_environments</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module contains objects that are used to describe the environments in a structure. The most detailed object</span>
<span class="sd">(StructureEnvironments) contains a very thorough analysis of the environments of a given atom but is difficult to</span>
<span class="sd">used as such. The LightStructureEnvironments object is a lighter version that is obtained by applying a &quot;strategy&quot;</span>
<span class="sd">on the StructureEnvironments object. Basically, the LightStructureEnvironments provides the coordination environment(s)</span>
<span class="sd">and possibly some fraction corresponding to these.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;David Waroquiers&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2012, The Materials Project&quot;</span>
<span class="n">__credits__</span> <span class="o">=</span> <span class="s2">&quot;Geoffroy Hautier&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;2.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;David Waroquiers&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;david.waroquiers@gmail.com&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Feb 20, 2016&quot;</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">OrderedDict</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.sites</span> <span class="kn">import</span> <span class="n">PeriodicSite</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span><span class="p">,</span> <span class="n">MontyDecoder</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">Element</span><span class="p">,</span> <span class="n">Specie</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">jsanitize</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.coordination_environments.voronoi</span> <span class="kn">import</span> <span class="n">DetailedVoronoiContainer</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.utils.chemenv_errors</span> <span class="kn">import</span> <span class="n">ChemenvError</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.coordination_environments.coordination_geometries</span> <span class="kn">import</span> <span class="n">AllCoordinationGeometries</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.utils.defs_utils</span> <span class="kn">import</span> <span class="n">AdditionalConditions</span>

<span class="n">allcg</span> <span class="o">=</span> <span class="n">AllCoordinationGeometries</span><span class="p">()</span>
<span class="n">symbol_cn_mapping</span> <span class="o">=</span> <span class="n">allcg</span><span class="o">.</span><span class="n">get_symbol_cn_mapping</span><span class="p">()</span>


<div class="viewcode-block" id="StructureEnvironments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments">[docs]</a><span class="k">class</span> <span class="nc">StructureEnvironments</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class used to store the chemical environments of a given structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">AC</span> <span class="o">=</span> <span class="n">AdditionalConditions</span><span class="p">()</span>

<div class="viewcode-block" id="StructureEnvironments.NeighborsSet"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.NeighborsSet">[docs]</a>    <span class="k">class</span> <span class="nc">NeighborsSet</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Class used to store a given set of neighbors of a given site (based on the detailed_voronoi).</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">detailed_voronoi</span><span class="p">,</span> <span class="n">site_voronoi_indices</span><span class="p">,</span> <span class="n">sources</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Constructor for NeighborsSet.</span>

<span class="sd">            Args:</span>
<span class="sd">                structure: Structure object.</span>
<span class="sd">                isite: Index of the site for which neighbors are stored in this NeighborsSet.</span>
<span class="sd">                detailed_voronoi: Corresponding DetailedVoronoiContainer object containing all the possible</span>
<span class="sd">                    neighbors of the give site.</span>
<span class="sd">                site_voronoi_indices: Indices of the voronoi sites in the DetailedVoronoiContainer object that</span>
<span class="sd">                    make up this NeighborsSet.</span>
<span class="sd">                sources: Sources for this NeighborsSet, i.e. how this NeighborsSet was generated.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">isite</span> <span class="o">=</span> <span class="n">isite</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span> <span class="o">=</span> <span class="n">detailed_voronoi</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span> <span class="o">=</span> <span class="n">detailed_voronoi</span><span class="o">.</span><span class="n">voronoi_list2</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span>
            <span class="n">myset</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">site_voronoi_indices</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">myset</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">site_voronoi_indices</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Set of neighbors contains duplicates !&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">myset</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">sources</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">sources</span> <span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;origin&#39;</span><span class="p">:</span> <span class="s1">&#39;UNKNOWN&#39;</span><span class="p">}]</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">sources</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">sources</span> <span class="o">=</span> <span class="n">sources</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">sources</span> <span class="o">=</span> <span class="p">[</span><span class="n">sources</span><span class="p">]</span>

<div class="viewcode-block" id="StructureEnvironments.NeighborsSet.get_neighb_voronoi_indices"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.NeighborsSet.get_neighb_voronoi_indices">[docs]</a>        <span class="k">def</span> <span class="nf">get_neighb_voronoi_indices</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">permutation</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Return the indices in the detailed_voronoi corresponding to the current permutation.</span>

<span class="sd">            Args:</span>
<span class="sd">                permutation: Current permutation for which the indices in the detailed_voronoi are needed.</span>

<span class="sd">            Returns: List of indices in the detailed_voronoi.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">permutation</span><span class="p">]</span></div>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">neighb_coords</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Coordinates of neighbors for this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;site&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">coords</span> <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">neighb_coordsOpt</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Optimized access to the coordinates of neighbors for this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span><span class="o">.</span><span class="n">voronoi_list_coords</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">neighb_sites</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Neighbors for this NeighborsSet as pymatgen Sites.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;site&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">neighb_sites_and_indices</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            List of neighbors for this NeighborsSet as pymatgen Sites and their index in the original structure.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[{</span><span class="s1">&#39;site&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;site&#39;</span><span class="p">],</span>
                     <span class="s1">&#39;index&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;index&#39;</span><span class="p">]}</span> <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">coords</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Coordinates of the current central atom and its neighbors for this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">coords</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">coords</span><span class="p">]</span>
            <span class="n">coords</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">neighb_coords</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">coords</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">normalized_distances</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Normalized distances to each neighbor in this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;normalized_distance&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">normalized_angles</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Normalized angles for each neighbor in this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;normalized_angle&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">distances</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Distances to each neighbor in this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;distance&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">angles</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Angles for each neighbor in this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;angle&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">]</span>

        <span class="c1"># @property</span>
        <span class="c1"># def sphere_fraction_angles(self):</span>
        <span class="c1">#     return [0.25 * self.voronoi[inb][&#39;angle&#39;] / np.pi for inb in self.site_voronoi_indices]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">info</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Summarized information about this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">was</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalized_angles</span>
            <span class="n">wds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalized_distances</span>
            <span class="n">angles</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angles</span>
            <span class="n">distances</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">distances</span>
            <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;normalized_angles&#39;</span><span class="p">:</span> <span class="n">was</span><span class="p">,</span>
                    <span class="s1">&#39;normalized_distances&#39;</span><span class="p">:</span> <span class="n">wds</span><span class="p">,</span>
                    <span class="s1">&#39;normalized_angles_sum&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">was</span><span class="p">),</span>
                    <span class="s1">&#39;normalized_angles_mean&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">was</span><span class="p">),</span>
                    <span class="s1">&#39;normalized_angles_std&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">was</span><span class="p">),</span>
                    <span class="s1">&#39;normalized_angles_min&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">was</span><span class="p">),</span>
                    <span class="s1">&#39;normalized_angles_max&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">was</span><span class="p">),</span>
                    <span class="s1">&#39;normalized_distances_mean&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">wds</span><span class="p">),</span>
                    <span class="s1">&#39;normalized_distances_std&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">wds</span><span class="p">),</span>
                    <span class="s1">&#39;normalized_distances_min&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">wds</span><span class="p">),</span>
                    <span class="s1">&#39;normalized_distances_max&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">wds</span><span class="p">),</span>
                    <span class="s1">&#39;angles&#39;</span><span class="p">:</span> <span class="n">angles</span><span class="p">,</span>
                    <span class="s1">&#39;distances&#39;</span><span class="p">:</span> <span class="n">distances</span><span class="p">,</span>
                    <span class="s1">&#39;angles_sum&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">angles</span><span class="p">),</span>
                    <span class="s1">&#39;angles_mean&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">angles</span><span class="p">),</span>
                    <span class="s1">&#39;angles_std&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">angles</span><span class="p">),</span>
                    <span class="s1">&#39;angles_min&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">angles</span><span class="p">),</span>
                    <span class="s1">&#39;angles_max&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">angles</span><span class="p">),</span>
                    <span class="s1">&#39;distances_mean&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">distances</span><span class="p">),</span>
                    <span class="s1">&#39;distances_std&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">distances</span><span class="p">),</span>
                    <span class="s1">&#39;distances_min&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">distances</span><span class="p">),</span>
                    <span class="s1">&#39;distances_max&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">distances</span><span class="p">)</span>
                    <span class="p">}</span>

<div class="viewcode-block" id="StructureEnvironments.NeighborsSet.distance_plateau"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.NeighborsSet.distance_plateau">[docs]</a>        <span class="k">def</span> <span class="nf">distance_plateau</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Returns the distances plateau&#39;s for this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">all_nbs_normalized_distances_sorted</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">([</span><span class="n">nb</span><span class="p">[</span><span class="s1">&#39;normalized_distance&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">nb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">],</span>
                                                         <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="n">maxdist</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">normalized_distances</span><span class="p">)</span>
            <span class="n">plateau</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">for</span> <span class="n">idist</span><span class="p">,</span> <span class="n">dist</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">all_nbs_normalized_distances_sorted</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">dist</span><span class="p">,</span> <span class="n">maxdist</span><span class="p">,</span>
                              <span class="n">rtol</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">atol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span><span class="o">.</span><span class="n">normalized_distance_tolerance</span><span class="p">):</span>
                    <span class="k">if</span> <span class="n">idist</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">plateau</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">plateau</span> <span class="o">=</span> <span class="n">all_nbs_normalized_distances_sorted</span><span class="p">[</span><span class="n">idist</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">maxdist</span>
                    <span class="k">break</span>
            <span class="k">if</span> <span class="n">plateau</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Plateau not found ...&#39;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">plateau</span></div>

<div class="viewcode-block" id="StructureEnvironments.NeighborsSet.angle_plateau"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.NeighborsSet.angle_plateau">[docs]</a>        <span class="k">def</span> <span class="nf">angle_plateau</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Returns the angles plateau&#39;s for this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">all_nbs_normalized_angles_sorted</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">([</span><span class="n">nb</span><span class="p">[</span><span class="s1">&#39;normalized_angle&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">nb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">])</span>
            <span class="n">minang</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">normalized_angles</span><span class="p">)</span>
            <span class="c1"># print(&#39;minang&#39;, minang)</span>
            <span class="c1"># print(&#39;all_nbs_normalized_angles_sorted&#39;, all_nbs_normalized_angles_sorted)</span>
            <span class="k">for</span> <span class="n">nb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="n">nb</span><span class="p">)</span>
            <span class="n">plateau</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">for</span> <span class="n">iang</span><span class="p">,</span> <span class="n">ang</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">all_nbs_normalized_angles_sorted</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">ang</span><span class="p">,</span> <span class="n">minang</span><span class="p">,</span>
                              <span class="n">rtol</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">atol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span><span class="o">.</span><span class="n">normalized_angle_tolerance</span><span class="p">):</span>
                    <span class="k">if</span> <span class="n">iang</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">plateau</span> <span class="o">=</span> <span class="n">minang</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">plateau</span> <span class="o">=</span> <span class="n">minang</span> <span class="o">-</span> <span class="n">all_nbs_normalized_angles_sorted</span><span class="p">[</span><span class="n">iang</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span>
                    <span class="k">break</span>
            <span class="k">if</span> <span class="n">plateau</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Plateau not found ...&#39;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">plateau</span></div>

<div class="viewcode-block" id="StructureEnvironments.NeighborsSet.voronoi_grid_surface_points"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.NeighborsSet.voronoi_grid_surface_points">[docs]</a>        <span class="k">def</span> <span class="nf">voronoi_grid_surface_points</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">additional_condition</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">other_origins</span><span class="o">=</span><span class="s1">&#39;DO_NOTHING&#39;</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Get the surface points in the Voronoi grid for this neighbor from the sources.</span>
<span class="sd">            The general shape of the points should look like a staircase such as in the following figure :</span>

<span class="sd">               ^</span>
<span class="sd">            0.0|</span>
<span class="sd">               |</span>
<span class="sd">               |      B----C</span>
<span class="sd">               |      |    |</span>
<span class="sd">               |      |    |</span>
<span class="sd">            a  |      k    D-------E</span>
<span class="sd">            n  |      |            |</span>
<span class="sd">            g  |      |            |</span>
<span class="sd">            l  |      |            |</span>
<span class="sd">            e  |      j            F----n---------G</span>
<span class="sd">               |      |                           |</span>
<span class="sd">               |      |                           |</span>
<span class="sd">               |      A----g-------h----i---------H</span>
<span class="sd">               |</span>
<span class="sd">               |</span>
<span class="sd">            1.0+-------------------------------------------------&gt;</span>
<span class="sd">              1.0              distance              2.0   -&gt;+Inf</span>

<span class="sd">            Args:</span>
<span class="sd">                additional_condition: Additional condition for the neighbors.</span>
<span class="sd">                other_origins: What to do with sources that do not come from the Voronoi grid (e.g. &quot;from hints&quot;).</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">mysrc</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">src</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sources</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">src</span><span class="p">[</span><span class="s1">&#39;origin&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;dist_ang_ac_voronoi&#39;</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">src</span><span class="p">[</span><span class="s1">&#39;ac&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="n">additional_condition</span><span class="p">:</span>
                        <span class="k">continue</span>
                    <span class="n">mysrc</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">src</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">other_origins</span> <span class="o">==</span> <span class="s1">&#39;DO_NOTHING&#39;</span><span class="p">:</span>
                        <span class="k">continue</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;Nothing implemented for other sources ...&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">mysrc</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">None</span>

            <span class="n">dists</span> <span class="o">=</span> <span class="p">[</span><span class="n">src</span><span class="p">[</span><span class="s1">&#39;dp_dict&#39;</span><span class="p">][</span><span class="s1">&#39;min&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">src</span> <span class="ow">in</span> <span class="n">mysrc</span><span class="p">]</span>
            <span class="n">angs</span> <span class="o">=</span> <span class="p">[</span><span class="n">src</span><span class="p">[</span><span class="s1">&#39;ap_dict&#39;</span><span class="p">][</span><span class="s1">&#39;max&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">src</span> <span class="ow">in</span> <span class="n">mysrc</span><span class="p">]</span>
            <span class="n">next_dists</span> <span class="o">=</span> <span class="p">[</span><span class="n">src</span><span class="p">[</span><span class="s1">&#39;dp_dict&#39;</span><span class="p">][</span><span class="s1">&#39;next&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">src</span> <span class="ow">in</span> <span class="n">mysrc</span><span class="p">]</span>
            <span class="n">next_angs</span> <span class="o">=</span> <span class="p">[</span><span class="n">src</span><span class="p">[</span><span class="s1">&#39;ap_dict&#39;</span><span class="p">][</span><span class="s1">&#39;next&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">src</span> <span class="ow">in</span> <span class="n">mysrc</span><span class="p">]</span>

            <span class="n">points_dict</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>

            <span class="n">pdists</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">pangs</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="k">for</span> <span class="n">isrc</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">mysrc</span><span class="p">)):</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">any</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">pdists</span><span class="p">,</span> <span class="n">dists</span><span class="p">[</span><span class="n">isrc</span><span class="p">])):</span>
                    <span class="n">pdists</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dists</span><span class="p">[</span><span class="n">isrc</span><span class="p">])</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">any</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">pdists</span><span class="p">,</span> <span class="n">next_dists</span><span class="p">[</span><span class="n">isrc</span><span class="p">])):</span>
                    <span class="n">pdists</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">next_dists</span><span class="p">[</span><span class="n">isrc</span><span class="p">])</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">any</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">pangs</span><span class="p">,</span> <span class="n">angs</span><span class="p">[</span><span class="n">isrc</span><span class="p">])):</span>
                    <span class="n">pangs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">angs</span><span class="p">[</span><span class="n">isrc</span><span class="p">])</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">any</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">pangs</span><span class="p">,</span> <span class="n">next_angs</span><span class="p">[</span><span class="n">isrc</span><span class="p">])):</span>
                    <span class="n">pangs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">next_angs</span><span class="p">[</span><span class="n">isrc</span><span class="p">])</span>
                <span class="n">d1_indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argwhere</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">pdists</span><span class="p">,</span> <span class="n">dists</span><span class="p">[</span><span class="n">isrc</span><span class="p">]))</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">d1_indices</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Distance parameter not found ...&#39;</span><span class="p">)</span>
                <span class="n">d2_indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argwhere</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">pdists</span><span class="p">,</span> <span class="n">next_dists</span><span class="p">[</span><span class="n">isrc</span><span class="p">]))</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">d2_indices</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Distance parameter not found ...&#39;</span><span class="p">)</span>
                <span class="n">a1_indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argwhere</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">pangs</span><span class="p">,</span> <span class="n">angs</span><span class="p">[</span><span class="n">isrc</span><span class="p">]))</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">a1_indices</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Angle parameter not found ...&#39;</span><span class="p">)</span>
                <span class="n">a2_indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argwhere</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">pangs</span><span class="p">,</span> <span class="n">next_angs</span><span class="p">[</span><span class="n">isrc</span><span class="p">]))</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">a2_indices</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Angle parameter not found ...&#39;</span><span class="p">)</span>
                <span class="n">id1</span> <span class="o">=</span> <span class="n">d1_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="n">id2</span> <span class="o">=</span> <span class="n">d2_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="n">ia1</span> <span class="o">=</span> <span class="n">a1_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="n">ia2</span> <span class="o">=</span> <span class="n">a2_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="k">for</span> <span class="n">id_ia</span> <span class="ow">in</span> <span class="p">[(</span><span class="n">id1</span><span class="p">,</span> <span class="n">ia1</span><span class="p">),</span> <span class="p">(</span><span class="n">id1</span><span class="p">,</span> <span class="n">ia2</span><span class="p">),</span> <span class="p">(</span><span class="n">id2</span><span class="p">,</span> <span class="n">ia1</span><span class="p">),</span> <span class="p">(</span><span class="n">id2</span><span class="p">,</span> <span class="n">ia2</span><span class="p">)]:</span>
                    <span class="k">if</span> <span class="n">id_ia</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">points_dict</span><span class="p">:</span>
                        <span class="n">points_dict</span><span class="p">[</span><span class="n">id_ia</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
                    <span class="n">points_dict</span><span class="p">[</span><span class="n">id_ia</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="n">new_pts</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">pt</span><span class="p">,</span> <span class="n">pt_nb</span> <span class="ow">in</span> <span class="n">points_dict</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="n">pt_nb</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">new_pts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>

            <span class="n">sorted_points</span> <span class="o">=</span> <span class="p">[(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)]</span>
            <span class="n">move_ap_index</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
                <span class="n">last_pt</span> <span class="o">=</span> <span class="n">sorted_points</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">move_ap_index</span><span class="p">:</span>  <span class="c1"># &quot;Move&quot; the angle parameter</span>
                    <span class="n">idp</span> <span class="o">=</span> <span class="n">last_pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">iap</span> <span class="o">=</span> <span class="kc">None</span>
                    <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">new_pts</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">idp</span> <span class="ow">and</span> <span class="n">pt</span> <span class="o">!=</span> <span class="n">last_pt</span><span class="p">:</span>
                            <span class="n">iap</span> <span class="o">=</span> <span class="n">pt</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                            <span class="k">break</span>
                <span class="k">else</span><span class="p">:</span>  <span class="c1"># &quot;Move&quot; the distance parameter</span>
                    <span class="n">idp</span> <span class="o">=</span> <span class="kc">None</span>
                    <span class="n">iap</span> <span class="o">=</span> <span class="n">last_pt</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                    <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">new_pts</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">pt</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">iap</span> <span class="ow">and</span> <span class="n">pt</span> <span class="o">!=</span> <span class="n">last_pt</span><span class="p">:</span>
                            <span class="n">idp</span> <span class="o">=</span> <span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                            <span class="k">break</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">idp</span><span class="p">,</span> <span class="n">iap</span><span class="p">)</span> <span class="o">==</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">):</span>
                    <span class="k">break</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">idp</span><span class="p">,</span> <span class="n">iap</span><span class="p">)</span> <span class="ow">in</span> <span class="n">sorted_points</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Error sorting points ...&#39;</span><span class="p">)</span>
                <span class="n">sorted_points</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">idp</span><span class="p">,</span> <span class="n">iap</span><span class="p">))</span>
                <span class="n">move_ap_index</span> <span class="o">=</span> <span class="ow">not</span> <span class="n">move_ap_index</span>

            <span class="n">points</span> <span class="o">=</span> <span class="p">[(</span><span class="n">pdists</span><span class="p">[</span><span class="n">idp</span><span class="p">],</span> <span class="n">pangs</span><span class="p">[</span><span class="n">iap</span><span class="p">])</span> <span class="k">for</span> <span class="p">(</span><span class="n">idp</span><span class="p">,</span> <span class="n">iap</span><span class="p">)</span> <span class="ow">in</span> <span class="n">sorted_points</span><span class="p">]</span>
            <span class="k">return</span> <span class="n">points</span></div>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">source</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Returns the source of this NeighborsSet (how it was generated, e.g. from which Voronoi cut-offs, or from</span>
<span class="sd">            hints).</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sources</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Number of sources different from 1 !&#39;</span><span class="p">)</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sources</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

<div class="viewcode-block" id="StructureEnvironments.NeighborsSet.add_source"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.NeighborsSet.add_source">[docs]</a>        <span class="k">def</span> <span class="nf">add_source</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Add a source to this NeighborsSet.</span>

<span class="sd">            Args:</span>
<span class="sd">                source: Information about the generation of this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">if</span> <span class="n">source</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sources</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">source</span><span class="p">)</span></div>

        <span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">)</span>

        <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">)</span>

        <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">isite</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">isite</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">site_voronoi_indices</span>

        <span class="k">def</span> <span class="fm">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
            <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span> <span class="o">==</span> <span class="n">other</span>

        <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="n">out</span> <span class="o">=</span> <span class="s1">&#39;Neighbors Set for site #</span><span class="si">{:d}</span><span class="s1"> :</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">isite</span><span class="p">)</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39; - Coordination number : </span><span class="si">{:d}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39; - Voronoi indices : </span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s1">&#39;</span><span class="si">{:d}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">site_voronoi_index</span><span class="p">)</span>
                                                                 <span class="k">for</span> <span class="n">site_voronoi_index</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">]))</span>
            <span class="k">return</span> <span class="n">out</span>

<div class="viewcode-block" id="StructureEnvironments.NeighborsSet.as_dict"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.NeighborsSet.as_dict">[docs]</a>        <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            A JSON serializable dict representation of the NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;isite&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">isite</span><span class="p">,</span>
                    <span class="s1">&#39;site_voronoi_indices&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_voronoi_indices</span><span class="p">,</span>
                    <span class="s1">&#39;sources&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">sources</span><span class="p">}</span></div>

<div class="viewcode-block" id="StructureEnvironments.NeighborsSet.from_dict"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.NeighborsSet.from_dict">[docs]</a>        <span class="nd">@classmethod</span>
        <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">dd</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">detailed_voronoi</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Reconstructs the NeighborsSet algorithm from its JSON serializable dict representation, together with</span>
<span class="sd">            the structure and the DetailedVoronoiContainer.</span>

<span class="sd">            As an inner (nested) class, the NeighborsSet is not supposed to be used anywhere else that inside the</span>
<span class="sd">            StructureEnvironments. The from_dict method is thus using the structure and  detailed_voronoi when</span>
<span class="sd">            reconstructing itself. These two are both in the StructureEnvironments object.</span>

<span class="sd">            Args:</span>
<span class="sd">                dd: a JSON serializable dict representation of a NeighborsSet.</span>
<span class="sd">                structure: The structure.</span>
<span class="sd">                detailed_voronoi: The Voronoi object containing all the neighboring atoms from which the subset of</span>
<span class="sd">                    neighbors for this NeighborsSet is extracted.</span>

<span class="sd">            Returns: a NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span>
                       <span class="n">isite</span><span class="o">=</span><span class="n">dd</span><span class="p">[</span><span class="s1">&#39;isite&#39;</span><span class="p">],</span>
                       <span class="n">detailed_voronoi</span><span class="o">=</span><span class="n">detailed_voronoi</span><span class="p">,</span>
                       <span class="n">site_voronoi_indices</span><span class="o">=</span><span class="n">dd</span><span class="p">[</span><span class="s1">&#39;site_voronoi_indices&#39;</span><span class="p">],</span>
                       <span class="n">sources</span><span class="o">=</span><span class="n">dd</span><span class="p">[</span><span class="s1">&#39;sources&#39;</span><span class="p">])</span></div></div>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">voronoi</span><span class="p">,</span> <span class="n">valences</span><span class="p">,</span> <span class="n">sites_map</span><span class="p">,</span> <span class="n">equivalent_sites</span><span class="p">,</span>
                 <span class="n">ce_list</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">neighbors_sets</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">info</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor for the StructureEnvironments object.</span>

<span class="sd">        Args:</span>
<span class="sd">            voronoi: VoronoiContainer object for the structure.</span>
<span class="sd">            valences: Valences provided.</span>
<span class="sd">            sites_map: Mapping of equivalent sites to the unequivalent sites that have been computed.</span>
<span class="sd">            equivalent_sites: List of list of equivalent sites of the structure.</span>
<span class="sd">            ce_list: List of chemical environments.</span>
<span class="sd">            structure: Structure object.</span>
<span class="sd">            neighbors_sets: List of neighbors sets.</span>
<span class="sd">            info: Additional information for this StructureEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span> <span class="o">=</span> <span class="n">voronoi</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">=</span> <span class="n">valences</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sites_map</span> <span class="o">=</span> <span class="n">sites_map</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">equivalent_sites</span> <span class="o">=</span> <span class="n">equivalent_sites</span>
        <span class="c1"># self.struct_sites_to_irreducible_site_list_map = struct_sites_to_irreducible_site_list_map</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span> <span class="o">=</span> <span class="n">ce_list</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span>
        <span class="k">if</span> <span class="n">neighbors_sets</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span> <span class="o">=</span> <span class="n">neighbors_sets</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">info</span> <span class="o">=</span> <span class="n">info</span>

<div class="viewcode-block" id="StructureEnvironments.init_neighbors_sets"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.init_neighbors_sets">[docs]</a>    <span class="k">def</span> <span class="nf">init_neighbors_sets</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">additional_conditions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">valences</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize the list of neighbors sets for the current site.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site under consideration.</span>
<span class="sd">            additional_conditions: Additional conditions to be used for the initialization of the list of</span>
<span class="sd">                neighbors sets, e.g. &quot;Only anion-cation bonds&quot;, ...</span>
<span class="sd">            valences: List of valences for each site in the structure (needed if an additional condition based on the</span>
<span class="sd">                valence is used, e.g. only anion-cation bonds).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">site_voronoi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="o">.</span><span class="n">voronoi_list2</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">site_voronoi</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="k">if</span> <span class="n">additional_conditions</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">additional_conditions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">AC</span><span class="o">.</span><span class="n">ALL</span>
        <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">AC</span><span class="o">.</span><span class="n">ONLY_ACB</span> <span class="ow">in</span> <span class="n">additional_conditions</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">AC</span><span class="o">.</span><span class="n">ONLY_ACB_AND_NO_E2SEB</span><span class="p">)</span> <span class="ow">and</span> <span class="n">valences</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">ChemenvError</span><span class="p">(</span><span class="s1">&#39;StructureEnvironments&#39;</span><span class="p">,</span> <span class="s1">&#39;init_neighbors_sets&#39;</span><span class="p">,</span>
                               <span class="s1">&#39;Valences are not given while only_anion_cation_bonds are allowed. Cannot continue&#39;</span><span class="p">)</span>
        <span class="n">site_distance_parameters</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="o">.</span><span class="n">neighbors_normalized_distances</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span>
        <span class="n">site_angle_parameters</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="o">.</span><span class="n">neighbors_normalized_angles</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span>
        <span class="c1"># Precompute distance conditions</span>
        <span class="n">distance_conditions</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">idp</span><span class="p">,</span> <span class="n">dp_dict</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">site_distance_parameters</span><span class="p">):</span>
            <span class="n">distance_conditions</span><span class="o">.</span><span class="n">append</span><span class="p">([])</span>
            <span class="k">for</span> <span class="n">inb</span><span class="p">,</span> <span class="n">voro_nb_dict</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">site_voronoi</span><span class="p">):</span>
                <span class="n">cond</span> <span class="o">=</span> <span class="n">inb</span> <span class="ow">in</span> <span class="n">dp_dict</span><span class="p">[</span><span class="s1">&#39;nb_indices&#39;</span><span class="p">]</span>
                <span class="n">distance_conditions</span><span class="p">[</span><span class="n">idp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cond</span><span class="p">)</span>
        <span class="c1"># Precompute angle conditions</span>
        <span class="n">angle_conditions</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">iap</span><span class="p">,</span> <span class="n">ap_dict</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">site_angle_parameters</span><span class="p">):</span>
            <span class="n">angle_conditions</span><span class="o">.</span><span class="n">append</span><span class="p">([])</span>
            <span class="k">for</span> <span class="n">inb</span><span class="p">,</span> <span class="n">voro_nb_dict</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">site_voronoi</span><span class="p">):</span>
                <span class="n">cond</span> <span class="o">=</span> <span class="n">inb</span> <span class="ow">in</span> <span class="n">ap_dict</span><span class="p">[</span><span class="s1">&#39;nb_indices&#39;</span><span class="p">]</span>
                <span class="n">angle_conditions</span><span class="p">[</span><span class="n">iap</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cond</span><span class="p">)</span>
        <span class="c1"># Precompute additional conditions</span>
        <span class="n">precomputed_additional_conditions</span> <span class="o">=</span> <span class="p">{</span><span class="n">ac</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">ac</span> <span class="ow">in</span> <span class="n">additional_conditions</span><span class="p">}</span>
        <span class="k">for</span> <span class="n">inb</span><span class="p">,</span> <span class="n">voro_nb_dict</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">site_voronoi</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">ac</span> <span class="ow">in</span> <span class="n">additional_conditions</span><span class="p">:</span>
                <span class="n">cond</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">AC</span><span class="o">.</span><span class="n">check_condition</span><span class="p">(</span><span class="n">condition</span><span class="o">=</span><span class="n">ac</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span>
                                               <span class="n">parameters</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;valences&#39;</span><span class="p">:</span> <span class="n">valences</span><span class="p">,</span>
                                                           <span class="s1">&#39;neighbor_index&#39;</span><span class="p">:</span> <span class="n">voro_nb_dict</span><span class="p">[</span><span class="s1">&#39;index&#39;</span><span class="p">],</span>
                                                           <span class="s1">&#39;site_index&#39;</span><span class="p">:</span> <span class="n">isite</span><span class="p">})</span>
                <span class="n">precomputed_additional_conditions</span><span class="p">[</span><span class="n">ac</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cond</span><span class="p">)</span>
        <span class="c1"># Add the neighbors sets based on the distance/angle/additional parameters</span>
        <span class="k">for</span> <span class="n">idp</span><span class="p">,</span> <span class="n">dp_dict</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">site_distance_parameters</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">iap</span><span class="p">,</span> <span class="n">ap_dict</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">site_angle_parameters</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">iac</span><span class="p">,</span> <span class="n">ac</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">additional_conditions</span><span class="p">):</span>
                    <span class="n">src</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;origin&#39;</span><span class="p">:</span> <span class="s1">&#39;dist_ang_ac_voronoi&#39;</span><span class="p">,</span>
                           <span class="s1">&#39;idp&#39;</span><span class="p">:</span> <span class="n">idp</span><span class="p">,</span> <span class="s1">&#39;iap&#39;</span><span class="p">:</span> <span class="n">iap</span><span class="p">,</span> <span class="s1">&#39;dp_dict&#39;</span><span class="p">:</span> <span class="n">dp_dict</span><span class="p">,</span> <span class="s1">&#39;ap_dict&#39;</span><span class="p">:</span> <span class="n">ap_dict</span><span class="p">,</span>
                           <span class="s1">&#39;iac&#39;</span><span class="p">:</span> <span class="n">iac</span><span class="p">,</span> <span class="s1">&#39;ac&#39;</span><span class="p">:</span> <span class="n">ac</span><span class="p">,</span> <span class="s1">&#39;ac_name&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">AC</span><span class="o">.</span><span class="n">CONDITION_DESCRIPTION</span><span class="p">[</span><span class="n">ac</span><span class="p">]}</span>
                    <span class="n">site_voronoi_indices</span> <span class="o">=</span> <span class="p">[</span><span class="n">inb</span> <span class="k">for</span> <span class="n">inb</span><span class="p">,</span> <span class="n">voro_nb_dict</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">site_voronoi</span><span class="p">)</span>
                                            <span class="k">if</span> <span class="p">(</span><span class="n">distance_conditions</span><span class="p">[</span><span class="n">idp</span><span class="p">][</span><span class="n">inb</span><span class="p">]</span> <span class="ow">and</span>
                                                <span class="n">angle_conditions</span><span class="p">[</span><span class="n">iap</span><span class="p">][</span><span class="n">inb</span><span class="p">]</span> <span class="ow">and</span>
                                                <span class="n">precomputed_additional_conditions</span><span class="p">[</span><span class="n">ac</span><span class="p">][</span><span class="n">inb</span><span class="p">])]</span>
                    <span class="n">nb_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">NeighborsSet</span><span class="p">(</span><span class="n">structure</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span>
                                               <span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span>
                                               <span class="n">detailed_voronoi</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">,</span>
                                               <span class="n">site_voronoi_indices</span><span class="o">=</span><span class="n">site_voronoi_indices</span><span class="p">,</span>
                                               <span class="n">sources</span><span class="o">=</span><span class="n">src</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">add_neighbors_set</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">nb_set</span><span class="o">=</span><span class="n">nb_set</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureEnvironments.add_neighbors_set"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.add_neighbors_set">[docs]</a>    <span class="k">def</span> <span class="nf">add_neighbors_set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">nb_set</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds a neighbor set to the list of neighbors sets for this site.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site under consideration.</span>
<span class="sd">            nb_set: NeighborsSet to be added.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">cn</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">nb_set</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">cn</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">nb_set_index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">nb_set</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">][</span><span class="n">nb_set_index</span><span class="p">]</span><span class="o">.</span><span class="n">add_source</span><span class="p">(</span><span class="n">nb_set</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nb_set</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureEnvironments.update_coordination_environments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.update_coordination_environments">[docs]</a>    <span class="k">def</span> <span class="nf">update_coordination_environments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">cn</span><span class="p">,</span> <span class="n">nb_set</span><span class="p">,</span> <span class="n">ce</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Updates the coordination environment for this site, coordination and neighbor set.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site to be updated.</span>
<span class="sd">            cn: Coordination to be updated.</span>
<span class="sd">            nb_set: Neighbors set to be updated.</span>
<span class="sd">            ce: ChemicalEnvironments object for this neighbors set.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="n">cn</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">nb_set_index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">nb_set</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Neighbors set not found in the structure environments&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">nb_set_index</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ce</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">nb_set_index</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">][</span><span class="n">nb_set_index</span><span class="p">]</span> <span class="o">=</span> <span class="n">ce</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Neighbors set not yet in ce_list !&#39;</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureEnvironments.update_site_info"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.update_site_info">[docs]</a>    <span class="k">def</span> <span class="nf">update_site_info</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">info_dict</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Update information about this site.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site for which info has to be updated.</span>
<span class="sd">            info_dict: Dictionary of information to be added for this site.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s1">&#39;sites_info&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="s1">&#39;sites_info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[{}</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">))]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="s1">&#39;sites_info&#39;</span><span class="p">][</span><span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">info_dict</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureEnvironments.get_coordination_environments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.get_coordination_environments">[docs]</a>    <span class="k">def</span> <span class="nf">get_coordination_environments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">cn</span><span class="p">,</span> <span class="n">nb_set</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the ChemicalEnvironments for a given site, coordination and neighbors set.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site for which the ChemicalEnvironments is looked for.</span>
<span class="sd">            cn: Coordination for which the ChemicalEnvironments is looked for.</span>
<span class="sd">            nb_set: Neighbors set for which the ChemicalEnvironments is looked for.</span>

<span class="sd">        Returns: a ChemicalEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">cn</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">]:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">nb_set_index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">nb_set</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">][</span><span class="n">nb_set_index</span><span class="p">]</span></div>

<div class="viewcode-block" id="StructureEnvironments.get_csm"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.get_csm">[docs]</a>    <span class="k">def</span> <span class="nf">get_csm</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">mp_symbol</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the continuous symmetry measure for a given site in the given coordination environment.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site.</span>
<span class="sd">            mp_symbol: Symbol of the coordination environment for which we want the continuous symmetry measure.</span>

<span class="sd">        Returns: Continuous symmetry measure of the given site in the given environment.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">csms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_csms</span><span class="p">(</span><span class="n">isite</span><span class="p">,</span> <span class="n">mp_symbol</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">csms</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">ChemenvError</span><span class="p">(</span><span class="s1">&#39;StructureEnvironments&#39;</span><span class="p">,</span>
                               <span class="s1">&#39;get_csm&#39;</span><span class="p">,</span>
                               <span class="s1">&#39;Number of csms for site #</span><span class="si">{}</span><span class="s1"> with &#39;</span>
                               <span class="s1">&#39;mp_symbol &quot;</span><span class="si">{}</span><span class="s1">&quot; = </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">isite</span><span class="p">),</span>
                                                            <span class="n">mp_symbol</span><span class="p">,</span>
                                                            <span class="nb">str</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">csms</span><span class="p">))))</span>
        <span class="k">return</span> <span class="n">csms</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="StructureEnvironments.get_csms"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.get_csms">[docs]</a>    <span class="k">def</span> <span class="nf">get_csms</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">mp_symbol</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the continuous symmetry measure(s) of site with index isite with respect to the</span>
<span class="sd">         perfect coordination environment with mp_symbol. For some environments, a given mp_symbol might not</span>
<span class="sd">         be available (if there is no voronoi parameters leading to a number of neighbours corresponding to</span>
<span class="sd">         the coordination number of environment mp_symbol). For some environments, a given mp_symbol might</span>
<span class="sd">         lead to more than one csm (when two or more different voronoi parameters lead to different neighbours</span>
<span class="sd">         but with same number of neighbours).</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site.</span>
<span class="sd">            mp_symbol: MP symbol of the perfect environment for which the csm has to be given.</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of csms for site isite with respect to geometry mp_symbol</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cn</span> <span class="o">=</span> <span class="n">symbol_cn_mapping</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">cn</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">]:</span>
            <span class="k">return</span> <span class="p">[]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">envs</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">]</span> <span class="k">for</span> <span class="n">envs</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">]]</span></div>

<div class="viewcode-block" id="StructureEnvironments.plot_csm_and_maps"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.plot_csm_and_maps">[docs]</a>    <span class="k">def</span> <span class="nf">plot_csm_and_maps</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">max_csm</span><span class="o">=</span><span class="mf">8.0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plotting of the coordination numbers of a given site for all the distfactor/angfactor parameters. If the</span>
<span class="sd">        chemical environments are given, a color map is added to the plot, with the lowest continuous symmetry measure</span>
<span class="sd">        as the value for the color of that distfactor/angfactor set.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site for which the plot has to be done</span>
<span class="sd">            max_csm: Maximum continuous symmetry measure to be shown.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
        <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Plotting Chemical Environments requires matplotlib ... exiting &quot;plot&quot; function&#39;</span><span class="p">)</span>
            <span class="k">return</span>
        <span class="n">fig</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_csm_and_maps</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">max_csm</span><span class="o">=</span><span class="n">max_csm</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">fig</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span></div>

<div class="viewcode-block" id="StructureEnvironments.get_csm_and_maps"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.get_csm_and_maps">[docs]</a>    <span class="k">def</span> <span class="nf">get_csm_and_maps</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">max_csm</span><span class="o">=</span><span class="mf">8.0</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">symmetry_measure_type</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plotting of the coordination numbers of a given site for all the distfactor/angfactor parameters. If the</span>
<span class="sd">        chemical environments are given, a color map is added to the plot, with the lowest continuous symmetry measure</span>
<span class="sd">        as the value for the color of that distfactor/angfactor set.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site for which the plot has to be done.</span>
<span class="sd">            max_csm: Maximum continuous symmetry measure to be shown.</span>
<span class="sd">            figsize: Size of the figure.</span>
<span class="sd">            symmetry_measure_type: Type of continuous symmetry measure to be used.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Matplotlib figure and axes representing the csm and maps.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
            <span class="kn">from</span> <span class="nn">matplotlib.gridspec</span> <span class="kn">import</span> <span class="n">GridSpec</span>
        <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Plotting Chemical Environments requires matplotlib ... exiting &quot;plot&quot; function&#39;</span><span class="p">)</span>
            <span class="k">return</span>

        <span class="k">if</span> <span class="n">symmetry_measure_type</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">symmetry_measure_type</span> <span class="o">=</span> <span class="s1">&#39;csm_wcs_ctwcc&#39;</span>
        <span class="c1"># Initializes the figure</span>
        <span class="k">if</span> <span class="n">figsize</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="n">figsize</span><span class="p">)</span>
        <span class="n">gs</span> <span class="o">=</span> <span class="n">GridSpec</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">hspace</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">wspace</span><span class="o">=</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="n">subplot</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="n">gs</span><span class="p">[:])</span>
        <span class="n">subplot_distang</span> <span class="o">=</span> <span class="n">subplot</span><span class="o">.</span><span class="n">twinx</span><span class="p">()</span>

        <span class="n">ix</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">cn_maps</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">all_wds</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">all_was</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">max_wd</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="k">for</span> <span class="n">cn</span><span class="p">,</span> <span class="n">nb_sets</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">inb_set</span><span class="p">,</span> <span class="n">nb_set</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">nb_sets</span><span class="p">):</span>
                <span class="n">ce</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">][</span><span class="n">inb_set</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">ce</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="n">mingeoms</span> <span class="o">=</span> <span class="n">ce</span><span class="o">.</span><span class="n">minimum_geometries</span><span class="p">(</span><span class="n">max_csm</span><span class="o">=</span><span class="n">max_csm</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">mingeoms</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="n">wds</span> <span class="o">=</span> <span class="n">nb_set</span><span class="o">.</span><span class="n">normalized_distances</span>
                <span class="n">max_wd</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">max_wd</span><span class="p">,</span> <span class="nb">max</span><span class="p">(</span><span class="n">wds</span><span class="p">))</span>
                <span class="n">all_wds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">wds</span><span class="p">)</span>
                <span class="n">all_was</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nb_set</span><span class="o">.</span><span class="n">normalized_angles</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">mp_symbol</span><span class="p">,</span> <span class="n">cg_dict</span> <span class="ow">in</span> <span class="n">mingeoms</span><span class="p">:</span>
                    <span class="n">csm</span> <span class="o">=</span> <span class="n">cg_dict</span><span class="p">[</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">][</span><span class="n">symmetry_measure_type</span><span class="p">]</span>
                    <span class="n">subplot</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">ix</span><span class="p">,</span> <span class="n">csm</span><span class="p">,</span> <span class="s1">&#39;ob&#39;</span><span class="p">)</span>
                    <span class="n">subplot</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">mp_symbol</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="n">ix</span><span class="p">,</span> <span class="n">csm</span><span class="p">))</span>
                <span class="n">cn_maps</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">cn</span><span class="p">,</span> <span class="n">inb_set</span><span class="p">))</span>
                <span class="n">ix</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="k">if</span> <span class="n">max_wd</span> <span class="o">&lt;</span> <span class="mf">1.225</span><span class="p">:</span>
            <span class="n">ymax_wd</span> <span class="o">=</span> <span class="mf">1.25</span>
            <span class="n">yticks_wd</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">ymax_wd</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">max_wd</span> <span class="o">&lt;</span> <span class="mf">1.36</span><span class="p">:</span>
            <span class="n">ymax_wd</span> <span class="o">=</span> <span class="mf">1.4</span>
            <span class="n">yticks_wd</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">ymax_wd</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">max_wd</span> <span class="o">&lt;</span> <span class="mf">1.45</span><span class="p">:</span>
            <span class="n">ymax_wd</span> <span class="o">=</span> <span class="mf">1.5</span>
            <span class="n">yticks_wd</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">ymax_wd</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">max_wd</span> <span class="o">&lt;</span> <span class="mf">1.55</span><span class="p">:</span>
            <span class="n">ymax_wd</span> <span class="o">=</span> <span class="mf">1.6</span>
            <span class="n">yticks_wd</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">ymax_wd</span><span class="p">,</span> <span class="mi">7</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">max_wd</span> <span class="o">&lt;</span> <span class="mf">1.75</span><span class="p">:</span>
            <span class="n">ymax_wd</span> <span class="o">=</span> <span class="mf">1.8</span>
            <span class="n">yticks_wd</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">ymax_wd</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">max_wd</span> <span class="o">&lt;</span> <span class="mf">1.95</span><span class="p">:</span>
            <span class="n">ymax_wd</span> <span class="o">=</span> <span class="mf">2.0</span>
            <span class="n">yticks_wd</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">ymax_wd</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">max_wd</span> <span class="o">&lt;</span> <span class="mf">2.35</span><span class="p">:</span>
            <span class="n">ymax_wd</span> <span class="o">=</span> <span class="mf">2.5</span>
            <span class="n">yticks_wd</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">ymax_wd</span><span class="p">,</span> <span class="mi">7</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">ymax_wd</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="mf">1.1</span> <span class="o">*</span> <span class="n">max_wd</span><span class="p">)</span>
            <span class="n">yticks_wd</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">ymax_wd</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>

        <span class="n">yticks_wa</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>

        <span class="n">frac_bottom</span> <span class="o">=</span> <span class="mf">0.05</span>
        <span class="n">frac_top</span> <span class="o">=</span> <span class="mf">0.05</span>
        <span class="n">frac_middle</span> <span class="o">=</span> <span class="mf">0.1</span>
        <span class="n">yamin</span> <span class="o">=</span> <span class="n">frac_bottom</span>
        <span class="n">yamax</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">-</span> <span class="n">frac_middle</span> <span class="o">/</span> <span class="mi">2</span>
        <span class="n">ydmin</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">+</span> <span class="n">frac_middle</span> <span class="o">/</span> <span class="mi">2</span>
        <span class="n">ydmax</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="n">frac_top</span>

        <span class="k">def</span> <span class="nf">yang</span><span class="p">(</span><span class="n">wa</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">(</span><span class="n">yamax</span> <span class="o">-</span> <span class="n">yamin</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">wa</span><span class="p">)</span> <span class="o">+</span> <span class="n">yamin</span>

        <span class="k">def</span> <span class="nf">ydist</span><span class="p">(</span><span class="n">wd</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">wd</span><span class="p">)</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">ymax_wd</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">ydmax</span> <span class="o">-</span> <span class="n">ydmin</span><span class="p">)</span> <span class="o">+</span> <span class="n">ydmin</span>

        <span class="k">for</span> <span class="n">ix</span><span class="p">,</span> <span class="n">was</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">all_was</span><span class="p">):</span>
            <span class="n">subplot_distang</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="mf">0.2</span> <span class="o">+</span> <span class="n">ix</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">ones_like</span><span class="p">(</span><span class="n">was</span><span class="p">),</span> <span class="n">yang</span><span class="p">(</span><span class="n">was</span><span class="p">),</span> <span class="s1">&#39;&lt;g&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">mod</span><span class="p">(</span><span class="n">ix</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">alpha</span> <span class="o">=</span> <span class="mf">0.3</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">alpha</span> <span class="o">=</span> <span class="mf">0.1</span>
            <span class="n">subplot_distang</span><span class="o">.</span><span class="n">fill_between</span><span class="p">([</span><span class="o">-</span><span class="mf">0.5</span> <span class="o">+</span> <span class="n">ix</span><span class="p">,</span> <span class="mf">0.5</span> <span class="o">+</span> <span class="n">ix</span><span class="p">],</span>
                                         <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">],</span> <span class="mf">0.0</span><span class="p">,</span>
                                         <span class="n">facecolor</span><span class="o">=</span><span class="s1">&#39;k&#39;</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="n">alpha</span><span class="p">,</span> <span class="n">zorder</span><span class="o">=-</span><span class="mi">1000</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">ix</span><span class="p">,</span> <span class="n">wds</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">all_wds</span><span class="p">):</span>
            <span class="n">subplot_distang</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="mf">0.2</span> <span class="o">+</span> <span class="n">ix</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">ones_like</span><span class="p">(</span><span class="n">wds</span><span class="p">),</span> <span class="n">ydist</span><span class="p">(</span><span class="n">wds</span><span class="p">),</span> <span class="s1">&#39;sm&#39;</span><span class="p">)</span>

        <span class="n">subplot_distang</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cn_maps</span><span class="p">)],</span> <span class="p">[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">],</span> <span class="s1">&#39;k--&#39;</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>

        <span class="n">yticks</span> <span class="o">=</span> <span class="n">yang</span><span class="p">(</span><span class="n">yticks_wa</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
        <span class="n">yticks</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">ydist</span><span class="p">(</span><span class="n">yticks_wd</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span>
        <span class="n">yticklabels</span> <span class="o">=</span> <span class="n">yticks_wa</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
        <span class="n">yticklabels</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">yticks_wd</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span>
        <span class="n">subplot_distang</span><span class="o">.</span><span class="n">set_yticks</span><span class="p">(</span><span class="n">yticks</span><span class="p">)</span>
        <span class="n">subplot_distang</span><span class="o">.</span><span class="n">set_yticklabels</span><span class="p">(</span><span class="n">yticklabels</span><span class="p">)</span>

        <span class="n">fake_subplot_ang</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="n">gs</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">frame_on</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="n">fake_subplot_dist</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="n">gs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">frame_on</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="n">fake_subplot_ang</span><span class="o">.</span><span class="n">set_yticks</span><span class="p">([])</span>
        <span class="n">fake_subplot_dist</span><span class="o">.</span><span class="n">set_yticks</span><span class="p">([])</span>
        <span class="n">fake_subplot_ang</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">([])</span>
        <span class="n">fake_subplot_dist</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">([])</span>
        <span class="n">fake_subplot_ang</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Angle parameter&#39;</span><span class="p">,</span> <span class="n">labelpad</span><span class="o">=</span><span class="mi">45</span><span class="p">,</span> <span class="n">rotation</span><span class="o">=-</span><span class="mi">90</span><span class="p">)</span>
        <span class="n">fake_subplot_dist</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Distance parameter&#39;</span><span class="p">,</span> <span class="n">labelpad</span><span class="o">=</span><span class="mi">45</span><span class="p">,</span> <span class="n">rotation</span><span class="o">=-</span><span class="mi">90</span><span class="p">)</span>
        <span class="n">fake_subplot_ang</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">set_label_position</span><span class="p">(</span><span class="s2">&quot;right&quot;</span><span class="p">)</span>
        <span class="n">fake_subplot_dist</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">set_label_position</span><span class="p">(</span><span class="s2">&quot;right&quot;</span><span class="p">)</span>

        <span class="n">subplot_distang</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">])</span>
        <span class="n">subplot</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">cn_maps</span><span class="p">)))</span>
        <span class="n">subplot</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Continuous symmetry measure&#39;</span><span class="p">)</span>
        <span class="n">subplot</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cn_maps</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span><span class="p">])</span>
        <span class="n">subplot_distang</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cn_maps</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span><span class="p">])</span>
        <span class="n">subplot</span><span class="o">.</span><span class="n">set_xticklabels</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">cn_map</span><span class="p">)</span> <span class="k">for</span> <span class="n">cn_map</span> <span class="ow">in</span> <span class="n">cn_maps</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">fig</span><span class="p">,</span> <span class="n">subplot</span></div>

<div class="viewcode-block" id="StructureEnvironments.get_environments_figure"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.get_environments_figure">[docs]</a>    <span class="k">def</span> <span class="nf">get_environments_figure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">plot_type</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="s1">&#39;Coordination numbers&#39;</span><span class="p">,</span> <span class="n">max_dist</span><span class="o">=</span><span class="mf">2.0</span><span class="p">,</span>
                                <span class="n">colormap</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                <span class="n">strategy</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plotting of the coordination environments of a given site for all the distfactor/angfactor regions. The</span>
<span class="sd">        chemical environments with the lowest continuous symmetry measure is shown for each distfactor/angfactor</span>
<span class="sd">        region as the value for the color of that distfactor/angfactor region (using a colormap).</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site for which the plot has to be done.</span>
<span class="sd">            plot_type: How to plot the coordinations.</span>
<span class="sd">            title: Title for the figure.</span>
<span class="sd">            max_dist: Maximum distance to be plotted when the plotting of the distance is set to &#39;initial_normalized&#39;</span>
<span class="sd">                or &#39;initial_real&#39; (Warning: this is not the same meaning in both cases! In the first case, the</span>
<span class="sd">                closest atom lies at a &quot;normalized&quot; distance of 1.0 so that 2.0 means refers to this normalized</span>
<span class="sd">                distance while in the second case, the real distance is used).</span>
<span class="sd">            colormap: Color map to be used for the continuous symmetry measure.</span>
<span class="sd">            figsize: Size of the figure.</span>
<span class="sd">            strategy: Whether to plot information about one of the Chemenv Strategies.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Matplotlib figure and axes representing the environments.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">mpl</span>
            <span class="kn">from</span> <span class="nn">matplotlib</span> <span class="kn">import</span> <span class="n">cm</span>
            <span class="kn">from</span> <span class="nn">matplotlib.colors</span> <span class="kn">import</span> <span class="n">Normalize</span>
            <span class="kn">from</span> <span class="nn">matplotlib.patches</span> <span class="kn">import</span> <span class="n">Polygon</span>
        <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Plotting Chemical Environments requires matplotlib ... exiting &quot;plot&quot; function&#39;</span><span class="p">)</span>
            <span class="k">return</span>

        <span class="c1"># Initializes the figure</span>
        <span class="k">if</span> <span class="n">figsize</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">fig</span> <span class="o">=</span> <span class="n">mpl</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">fig</span> <span class="o">=</span> <span class="n">mpl</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="n">figsize</span><span class="p">)</span>
        <span class="n">subplot</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>

        <span class="c1"># Initializes the distance and angle parameters</span>
        <span class="k">if</span> <span class="n">plot_type</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">plot_type</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;distance_parameter&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;initial_normalized&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
                         <span class="s1">&#39;angle_parameter&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;initial_normalized_inverted&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)}</span>
        <span class="k">if</span> <span class="n">colormap</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">mycm</span> <span class="o">=</span> <span class="n">cm</span><span class="o">.</span><span class="n">jet</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">mycm</span> <span class="o">=</span> <span class="n">colormap</span>
        <span class="n">mymin</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="n">mymax</span> <span class="o">=</span> <span class="mf">10.0</span>
        <span class="n">norm</span> <span class="o">=</span> <span class="n">Normalize</span><span class="p">(</span><span class="n">vmin</span><span class="o">=</span><span class="n">mymin</span><span class="p">,</span> <span class="n">vmax</span><span class="o">=</span><span class="n">mymax</span><span class="p">)</span>
        <span class="n">scalarmap</span> <span class="o">=</span> <span class="n">cm</span><span class="o">.</span><span class="n">ScalarMappable</span><span class="p">(</span><span class="n">norm</span><span class="o">=</span><span class="n">norm</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="n">mycm</span><span class="p">)</span>
        <span class="n">dist_limits</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">max_dist</span><span class="p">]</span>
        <span class="n">ang_limits</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">plot_type</span><span class="p">[</span><span class="s1">&#39;distance_parameter&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;one_minus_inverse_alpha_power_n&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">plot_type</span><span class="p">[</span><span class="s1">&#39;distance_parameter&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">exponent</span> <span class="o">=</span> <span class="mi">3</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">exponent</span> <span class="o">=</span> <span class="n">plot_type</span><span class="p">[</span><span class="s1">&#39;distance_parameter&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="s1">&#39;exponent&#39;</span><span class="p">]</span>
            <span class="n">xlabel</span> <span class="o">=</span> <span class="s1">&#39;Distance parameter : $1.0-</span><span class="se">\\</span><span class="s1">frac{{1.0}}{{</span><span class="se">\\</span><span class="s1">alpha^{{</span><span class="si">{:d}</span><span class="s1">}}}}$&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">exponent</span><span class="p">)</span>

            <span class="k">def</span> <span class="nf">dp_func</span><span class="p">(</span><span class="n">dp</span><span class="p">):</span>
                <span class="k">return</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">power</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="n">exponent</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">plot_type</span><span class="p">[</span><span class="s1">&#39;distance_parameter&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;initial_normalized&#39;</span><span class="p">:</span>
            <span class="n">xlabel</span> <span class="o">=</span> <span class="s1">&#39;Distance parameter : $</span><span class="se">\\</span><span class="s1">alpha$&#39;</span>

            <span class="k">def</span> <span class="nf">dp_func</span><span class="p">(</span><span class="n">dp</span><span class="p">):</span>
                <span class="k">return</span> <span class="n">dp</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Wrong value for distance parameter plot type &quot;</span><span class="si">{}</span><span class="s1">&quot;&#39;</span><span class="o">.</span>
                             <span class="nb">format</span><span class="p">(</span><span class="n">plot_type</span><span class="p">[</span><span class="s1">&#39;distance_parameter&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]))</span>

        <span class="k">if</span> <span class="n">plot_type</span><span class="p">[</span><span class="s1">&#39;angle_parameter&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;one_minus_gamma&#39;</span><span class="p">:</span>
            <span class="n">ylabel</span> <span class="o">=</span> <span class="s1">&#39;Angle parameter : $1.0-</span><span class="se">\\</span><span class="s1">gamma$&#39;</span>

            <span class="k">def</span> <span class="nf">ap_func</span><span class="p">(</span><span class="n">ap</span><span class="p">):</span>
                <span class="k">return</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="n">ap</span>
        <span class="k">elif</span> <span class="n">plot_type</span><span class="p">[</span><span class="s1">&#39;angle_parameter&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;initial_normalized_inverted&#39;</span><span class="p">,</span> <span class="s1">&#39;initial_normalized&#39;</span><span class="p">]:</span>
            <span class="n">ylabel</span> <span class="o">=</span> <span class="s1">&#39;Angle parameter : $</span><span class="se">\\</span><span class="s1">gamma$&#39;</span>

            <span class="k">def</span> <span class="nf">ap_func</span><span class="p">(</span><span class="n">ap</span><span class="p">):</span>
                <span class="k">return</span> <span class="n">ap</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Wrong value for angle parameter plot type &quot;</span><span class="si">{}</span><span class="s1">&quot;&#39;</span><span class="o">.</span>
                             <span class="nb">format</span><span class="p">(</span><span class="n">plot_type</span><span class="p">[</span><span class="s1">&#39;angle_parameter&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]))</span>
        <span class="n">dist_limits</span> <span class="o">=</span> <span class="p">[</span><span class="n">dp_func</span><span class="p">(</span><span class="n">dp</span><span class="p">)</span> <span class="k">for</span> <span class="n">dp</span> <span class="ow">in</span> <span class="n">dist_limits</span><span class="p">]</span>
        <span class="n">ang_limits</span> <span class="o">=</span> <span class="p">[</span><span class="n">ap_func</span><span class="p">(</span><span class="n">ap</span><span class="p">)</span> <span class="k">for</span> <span class="n">ap</span> <span class="ow">in</span> <span class="n">ang_limits</span><span class="p">]</span>

        <span class="k">for</span> <span class="n">cn</span><span class="p">,</span> <span class="n">cn_nb_sets</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">inb_set</span><span class="p">,</span> <span class="n">nb_set</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">cn_nb_sets</span><span class="p">):</span>
                <span class="n">nb_set_surface_pts</span> <span class="o">=</span> <span class="n">nb_set</span><span class="o">.</span><span class="n">voronoi_grid_surface_points</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">nb_set_surface_pts</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="n">ce</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">][</span><span class="n">inb_set</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">ce</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">mycolor</span> <span class="o">=</span> <span class="s1">&#39;w&#39;</span>
                    <span class="n">myinvcolor</span> <span class="o">=</span> <span class="s1">&#39;k&#39;</span>
                    <span class="n">mytext</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:d}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cn</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">mingeom</span> <span class="o">=</span> <span class="n">ce</span><span class="o">.</span><span class="n">minimum_geometry</span><span class="p">()</span>
                    <span class="k">if</span> <span class="n">mingeom</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="n">mp_symbol</span> <span class="o">=</span> <span class="n">mingeom</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                        <span class="n">csm</span> <span class="o">=</span> <span class="n">mingeom</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]</span>
                        <span class="n">mycolor</span> <span class="o">=</span> <span class="n">scalarmap</span><span class="o">.</span><span class="n">to_rgba</span><span class="p">(</span><span class="n">csm</span><span class="p">)</span>
                        <span class="n">myinvcolor</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">mycolor</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="n">mycolor</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="n">mycolor</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="mf">1.0</span><span class="p">]</span>
                        <span class="n">mytext</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mp_symbol</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">mycolor</span> <span class="o">=</span> <span class="s1">&#39;w&#39;</span>
                        <span class="n">myinvcolor</span> <span class="o">=</span> <span class="s1">&#39;k&#39;</span>
                        <span class="n">mytext</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:d}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cn</span><span class="p">)</span>
                <span class="n">nb_set_surface_pts</span> <span class="o">=</span> <span class="p">[(</span><span class="n">dp_func</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">ap_func</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span> <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">nb_set_surface_pts</span><span class="p">]</span>
                <span class="n">polygon</span> <span class="o">=</span> <span class="n">Polygon</span><span class="p">(</span><span class="n">nb_set_surface_pts</span><span class="p">,</span> <span class="n">closed</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">edgecolor</span><span class="o">=</span><span class="s1">&#39;k&#39;</span><span class="p">,</span> <span class="n">facecolor</span><span class="o">=</span><span class="n">mycolor</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">1.2</span><span class="p">)</span>
                <span class="n">subplot</span><span class="o">.</span><span class="n">add_patch</span><span class="p">(</span><span class="n">polygon</span><span class="p">)</span>
                <span class="n">myipt</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">nb_set_surface_pts</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span>
                <span class="n">ipt</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">myipt</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">myipt</span> <span class="o">!=</span> <span class="n">ipt</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Number of surface points not even&#39;</span><span class="p">)</span>
                <span class="n">patch_center</span> <span class="o">=</span> <span class="p">((</span><span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="nb">min</span><span class="p">(</span><span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="n">ipt</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">dist_limits</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span>
                                <span class="p">(</span><span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="n">ipt</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mf">0.06</span> <span class="ow">and</span>
                        <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">dist_limits</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">-</span> <span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mf">0.125</span><span class="p">):</span>
                    <span class="n">xytext</span> <span class="o">=</span> <span class="p">((</span><span class="nb">min</span><span class="p">(</span><span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">dist_limits</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">+</span> <span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span>
                              <span class="p">(</span><span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span>
                    <span class="n">subplot</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">mytext</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="n">xytext</span><span class="p">,</span>
                                     <span class="n">ha</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">myinvcolor</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="s1">&#39;x-small&#39;</span><span class="p">)</span>
                <span class="k">elif</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="n">ipt</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mf">0.1</span> <span class="ow">and</span>
                      <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="n">ipt</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">dist_limits</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">-</span> <span class="n">nb_set_surface_pts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mf">0.125</span><span class="p">):</span>
                    <span class="n">xytext</span> <span class="o">=</span> <span class="n">patch_center</span>
                    <span class="n">subplot</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">mytext</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="n">xytext</span><span class="p">,</span>
                                     <span class="n">ha</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">myinvcolor</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="s1">&#39;x-small&#39;</span><span class="p">)</span>

        <span class="n">subplot</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="n">title</span><span class="p">)</span>
        <span class="n">subplot</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="n">xlabel</span><span class="p">)</span>
        <span class="n">subplot</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="n">ylabel</span><span class="p">)</span>

        <span class="n">dist_limits</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
        <span class="n">ang_limits</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
        <span class="n">subplot</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="n">dist_limits</span><span class="p">)</span>
        <span class="n">subplot</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="n">ang_limits</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">strategy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">strategy</span><span class="o">.</span><span class="n">add_strategy_visualization_to_subplot</span><span class="p">(</span><span class="n">subplot</span><span class="o">=</span><span class="n">subplot</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                <span class="k">pass</span>
        <span class="k">if</span> <span class="n">plot_type</span><span class="p">[</span><span class="s1">&#39;angle_parameter&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;initial_normalized_inverted&#39;</span><span class="p">:</span>
            <span class="n">subplot</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>

        <span class="n">scalarmap</span><span class="o">.</span><span class="n">set_array</span><span class="p">([</span><span class="n">mymin</span><span class="p">,</span> <span class="n">mymax</span><span class="p">])</span>
        <span class="n">cb</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">scalarmap</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">subplot</span><span class="p">,</span> <span class="n">extend</span><span class="o">=</span><span class="s1">&#39;max&#39;</span><span class="p">)</span>
        <span class="n">cb</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="s1">&#39;Continuous symmetry measure&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">fig</span><span class="p">,</span> <span class="n">subplot</span></div>

<div class="viewcode-block" id="StructureEnvironments.plot_environments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.plot_environments">[docs]</a>    <span class="k">def</span> <span class="nf">plot_environments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">plot_type</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="s1">&#39;Coordination numbers&#39;</span><span class="p">,</span> <span class="n">max_dist</span><span class="o">=</span><span class="mf">2.0</span><span class="p">,</span>
                          <span class="n">figsize</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">strategy</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plotting of the coordination numbers of a given site for all the distfactor/angfactor parameters. If the</span>
<span class="sd">        chemical environments are given, a color map is added to the plot, with the lowest continuous symmetry measure</span>
<span class="sd">        as the value for the color of that distfactor/angfactor set.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site for which the plot has to be done.</span>
<span class="sd">            plot_type: How to plot the coordinations.</span>
<span class="sd">            title: Title for the figure.</span>
<span class="sd">            max_dist: Maximum distance to be plotted when the plotting of the distance is set to &#39;initial_normalized&#39;</span>
<span class="sd">                or &#39;initial_real&#39; (Warning: this is not the same meaning in both cases! In the first case, the</span>
<span class="sd">                closest atom lies at a &quot;normalized&quot; distance of 1.0 so that 2.0 means refers to this normalized</span>
<span class="sd">                distance while in the second case, the real distance is used).</span>
<span class="sd">            figsize: Size of the figure.</span>
<span class="sd">            strategy: Whether to plot information about one of the Chemenv Strategies.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">fig</span><span class="p">,</span> <span class="n">subplot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_environments_figure</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">plot_type</span><span class="o">=</span><span class="n">plot_type</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="n">title</span><span class="p">,</span> <span class="n">max_dist</span><span class="o">=</span><span class="n">max_dist</span><span class="p">,</span>
                                                    <span class="n">figsize</span><span class="o">=</span><span class="n">figsize</span><span class="p">,</span>
                                                    <span class="n">strategy</span><span class="o">=</span><span class="n">strategy</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">fig</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="n">fig</span><span class="o">.</span><span class="n">show</span><span class="p">()</span></div>

<div class="viewcode-block" id="StructureEnvironments.save_environments_figure"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.save_environments_figure">[docs]</a>    <span class="k">def</span> <span class="nf">save_environments_figure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">imagename</span><span class="o">=</span><span class="s1">&#39;image.png&#39;</span><span class="p">,</span> <span class="n">plot_type</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="s1">&#39;Coordination numbers&#39;</span><span class="p">,</span>
                                 <span class="n">max_dist</span><span class="o">=</span><span class="mf">2.0</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Saves the environments figure to a given file.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site for which the plot has to be done.</span>
<span class="sd">            imagename: Name of the file to which the figure has to be saved.</span>
<span class="sd">            plot_type: How to plot the coordinations.</span>
<span class="sd">            title: Title for the figure.</span>
<span class="sd">            max_dist: Maximum distance to be plotted when the plotting of the distance is set to &#39;initial_normalized&#39;</span>
<span class="sd">                or &#39;initial_real&#39; (Warning: this is not the same meaning in both cases! In the first case, the</span>
<span class="sd">                closest atom lies at a &quot;normalized&quot; distance of 1.0 so that 2.0 means refers to this normalized</span>
<span class="sd">                distance while in the second case, the real distance is used).</span>
<span class="sd">            figsize: Size of the figure.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">fig</span><span class="p">,</span> <span class="n">subplot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_environments_figure</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">plot_type</span><span class="o">=</span><span class="n">plot_type</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="n">title</span><span class="p">,</span> <span class="n">max_dist</span><span class="o">=</span><span class="n">max_dist</span><span class="p">,</span>
                                                    <span class="n">figsize</span><span class="o">=</span><span class="n">figsize</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">fig</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="n">fig</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="n">imagename</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureEnvironments.differences_wrt"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.differences_wrt">[docs]</a>    <span class="k">def</span> <span class="nf">differences_wrt</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return differences found in the current StructureEnvironments with respect to another StructureEnvironments.</span>

<span class="sd">        Args:</span>
<span class="sd">            other: A StructureEnvironments object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of differences between the two StructureEnvironments objects.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">differences</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">structure</span><span class="p">:</span>
            <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;structure&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;__eq__&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span>
                                <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="n">other</span><span class="o">.</span><span class="n">structure</span><span class="p">})</span>
            <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;PREVIOUS DIFFERENCE IS DISMISSIVE&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;differences_wrt&#39;</span><span class="p">})</span>
            <span class="k">return</span> <span class="n">differences</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">valences</span><span class="p">:</span>
            <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;valences&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;__eq__&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span><span class="p">,</span>
                                <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="n">other</span><span class="o">.</span><span class="n">valences</span><span class="p">})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="p">:</span>
            <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;info&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;__eq__&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">,</span>
                                <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="p">})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">voronoi</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="o">.</span><span class="n">is_close_to</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">voronoi</span><span class="p">):</span>
                <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;voronoi&#39;</span><span class="p">,</span>
                                    <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;__eq__&#39;</span><span class="p">,</span>
                                    <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">,</span>
                                    <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="n">other</span><span class="o">.</span><span class="n">voronoi</span><span class="p">})</span>
                <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;PREVIOUS DIFFERENCE IS DISMISSIVE&#39;</span><span class="p">,</span>
                                    <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;differences_wrt&#39;</span><span class="p">})</span>
                <span class="k">return</span> <span class="n">differences</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;voronoi&#39;</span><span class="p">,</span>
                                    <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;is_close_to&#39;</span><span class="p">,</span>
                                    <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="p">,</span>
                                    <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="n">other</span><span class="o">.</span><span class="n">voronoi</span><span class="p">})</span>
                <span class="c1"># TODO: make it possible to have &quot;close&quot; voronoi&#39;s</span>
                <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;PREVIOUS DIFFERENCE IS DISMISSIVE&#39;</span><span class="p">,</span>
                                    <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;differences_wrt&#39;</span><span class="p">})</span>
                <span class="k">return</span> <span class="n">differences</span>
        <span class="k">for</span> <span class="n">isite</span><span class="p">,</span> <span class="n">self_site_nb_sets</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">):</span>
            <span class="n">other_site_nb_sets</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">self_site_nb_sets</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">other_site_nb_sets</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;neighbors_sets[isite=</span><span class="si">{:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">isite</span><span class="p">),</span>
                                        <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;has_neighbors&#39;</span><span class="p">,</span>
                                        <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="s1">&#39;None&#39;</span><span class="p">,</span>
                                        <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="nb">set</span><span class="p">(</span><span class="n">other_site_nb_sets</span><span class="o">.</span><span class="n">keys</span><span class="p">())})</span>
                    <span class="k">continue</span>
            <span class="k">elif</span> <span class="n">other_site_nb_sets</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;neighbors_sets[isite=</span><span class="si">{:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">isite</span><span class="p">),</span>
                                    <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;has_neighbors&#39;</span><span class="p">,</span>
                                    <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="nb">set</span><span class="p">(</span><span class="n">self_site_nb_sets</span><span class="o">.</span><span class="n">keys</span><span class="p">()),</span>
                                    <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="s1">&#39;None&#39;</span><span class="p">})</span>
                <span class="k">continue</span>
            <span class="n">self_site_cns</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">self_site_nb_sets</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
            <span class="n">other_site_cns</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">other_site_nb_sets</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
            <span class="k">if</span> <span class="n">self_site_cns</span> <span class="o">!=</span> <span class="n">other_site_cns</span><span class="p">:</span>
                <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;neighbors_sets[isite=</span><span class="si">{:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">isite</span><span class="p">),</span>
                                    <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;coordination_numbers&#39;</span><span class="p">,</span>
                                    <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="n">self_site_cns</span><span class="p">,</span>
                                    <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="n">other_site_cns</span><span class="p">})</span>
            <span class="n">common_cns</span> <span class="o">=</span> <span class="n">self_site_cns</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">other_site_cns</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">cn</span> <span class="ow">in</span> <span class="n">common_cns</span><span class="p">:</span>
                <span class="n">other_site_cn_nb_sets</span> <span class="o">=</span> <span class="n">other_site_nb_sets</span><span class="p">[</span><span class="n">cn</span><span class="p">]</span>
                <span class="n">self_site_cn_nb_sets</span> <span class="o">=</span> <span class="n">self_site_nb_sets</span><span class="p">[</span><span class="n">cn</span><span class="p">]</span>
                <span class="n">set_self_site_cn_nb_sets</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">self_site_cn_nb_sets</span><span class="p">)</span>
                <span class="n">set_other_site_cn_nb_sets</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">other_site_cn_nb_sets</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">set_self_site_cn_nb_sets</span> <span class="o">!=</span> <span class="n">set_other_site_cn_nb_sets</span><span class="p">:</span>
                    <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;neighbors_sets[isite=</span><span class="si">{:d}</span><span class="s1">][cn=</span><span class="si">{:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">isite</span><span class="p">,</span> <span class="n">cn</span><span class="p">),</span>
                                        <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;neighbors_sets&#39;</span><span class="p">,</span>
                                        <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="n">self_site_cn_nb_sets</span><span class="p">,</span>
                                        <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="n">other_site_cn_nb_sets</span><span class="p">})</span>
                <span class="n">common_nb_sets</span> <span class="o">=</span> <span class="n">set_self_site_cn_nb_sets</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">set_other_site_cn_nb_sets</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">nb_set</span> <span class="ow">in</span> <span class="n">common_nb_sets</span><span class="p">:</span>
                    <span class="n">inb_set_self</span> <span class="o">=</span> <span class="n">self_site_cn_nb_sets</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">nb_set</span><span class="p">)</span>
                    <span class="n">inb_set_other</span> <span class="o">=</span> <span class="n">other_site_cn_nb_sets</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">nb_set</span><span class="p">)</span>
                    <span class="n">self_ce</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">][</span><span class="n">inb_set_self</span><span class="p">]</span>
                    <span class="n">other_ce</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn</span><span class="p">][</span><span class="n">inb_set_other</span><span class="p">]</span>
                    <span class="k">if</span> <span class="n">self_ce</span> <span class="o">!=</span> <span class="n">other_ce</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">self_ce</span><span class="o">.</span><span class="n">is_close_to</span><span class="p">(</span><span class="n">other_ce</span><span class="p">):</span>
                            <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;ce_list[isite=</span><span class="si">{:d}</span><span class="s1">][cn=</span><span class="si">{:d}</span><span class="s1">]&#39;</span>
                                                              <span class="s1">&#39;[inb_set=</span><span class="si">{:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">isite</span><span class="p">,</span> <span class="n">cn</span><span class="p">,</span> <span class="n">inb_set_self</span><span class="p">),</span>
                                                <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;__eq__&#39;</span><span class="p">,</span>
                                                <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="n">self_ce</span><span class="p">,</span>
                                                <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="n">other_ce</span><span class="p">})</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">differences</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;difference&#39;</span><span class="p">:</span> <span class="s1">&#39;ce_list[isite=</span><span class="si">{:d}</span><span class="s1">][cn=</span><span class="si">{:d}</span><span class="s1">]&#39;</span>
                                                              <span class="s1">&#39;[inb_set=</span><span class="si">{:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">isite</span><span class="p">,</span> <span class="n">cn</span><span class="p">,</span> <span class="n">inb_set_self</span><span class="p">),</span>
                                                <span class="s1">&#39;comparison&#39;</span><span class="p">:</span> <span class="s1">&#39;is_close_to&#39;</span><span class="p">,</span>
                                                <span class="s1">&#39;self&#39;</span><span class="p">:</span> <span class="n">self_ce</span><span class="p">,</span>
                                                <span class="s1">&#39;other&#39;</span><span class="p">:</span> <span class="n">other_ce</span><span class="p">})</span>
        <span class="k">return</span> <span class="n">differences</span></div>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">ce_list</span><span class="p">):</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">voronoi</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">valences</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">valences</span><span class="p">):</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sites_map</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">sites_map</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">equivalent_sites</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">equivalent_sites</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">structure</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">info</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">for</span> <span class="n">isite</span><span class="p">,</span> <span class="n">site_ces</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">):</span>
            <span class="n">site_nb_sets_self</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span>
            <span class="n">site_nb_sets_other</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">site_nb_sets_self</span> <span class="o">!=</span> <span class="n">site_nb_sets_other</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="n">site_ces</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">ce_list</span><span class="p">[</span><span class="n">isite</span><span class="p">]:</span>
                <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="kc">True</span>

    <span class="k">def</span> <span class="fm">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span> <span class="o">==</span> <span class="n">other</span>

<div class="viewcode-block" id="StructureEnvironments.as_dict"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Bson-serializable dict representation of the StructureEnvironments object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Bson-serializable dict representation of the StructureEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ce_list_dict</span> <span class="o">=</span> <span class="p">[{</span><span class="nb">str</span><span class="p">(</span><span class="n">cn</span><span class="p">):</span> <span class="p">[</span><span class="n">ce</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">if</span> <span class="n">ce</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">ce</span> <span class="ow">in</span> <span class="n">ce_dict</span><span class="p">[</span><span class="n">cn</span><span class="p">]]</span>
                         <span class="k">for</span> <span class="n">cn</span> <span class="ow">in</span> <span class="n">ce_dict</span><span class="p">}</span> <span class="k">if</span> <span class="n">ce_dict</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">ce_dict</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ce_list</span><span class="p">]</span>
        <span class="n">nbs_sets_dict</span> <span class="o">=</span> <span class="p">[{</span><span class="nb">str</span><span class="p">(</span><span class="n">cn</span><span class="p">):</span> <span class="p">[</span><span class="n">nb_set</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">for</span> <span class="n">nb_set</span> <span class="ow">in</span> <span class="n">nb_sets</span><span class="p">]</span>
                          <span class="k">for</span> <span class="n">cn</span><span class="p">,</span> <span class="n">nb_sets</span> <span class="ow">in</span> <span class="n">site_nbs_sets</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
                         <span class="k">if</span> <span class="n">site_nbs_sets</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
                         <span class="k">for</span> <span class="n">site_nbs_sets</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">]</span>
        <span class="n">info_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="n">val</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;sites_info&#39;</span><span class="p">]}</span>
        <span class="n">info_dict</span><span class="p">[</span><span class="s1">&#39;sites_info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;nb_sets_info&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">cn</span><span class="p">):</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">inb_set</span><span class="p">):</span> <span class="n">nb_set_info</span>
                                                               <span class="k">for</span> <span class="n">inb_set</span><span class="p">,</span> <span class="n">nb_set_info</span> <span class="ow">in</span> <span class="n">cn_sets</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
                                                     <span class="k">for</span> <span class="n">cn</span><span class="p">,</span> <span class="n">cn_sets</span> <span class="ow">in</span> <span class="n">site_info</span><span class="p">[</span><span class="s1">&#39;nb_sets_info&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()},</span>
                                    <span class="s1">&#39;time&#39;</span><span class="p">:</span> <span class="n">site_info</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]}</span> <span class="k">if</span> <span class="s1">&#39;nb_sets_info&#39;</span> <span class="ow">in</span> <span class="n">site_info</span> <span class="k">else</span> <span class="p">{}</span>
                                   <span class="k">for</span> <span class="n">site_info</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="s1">&#39;sites_info&#39;</span><span class="p">]]</span>

        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
                <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                <span class="s2">&quot;voronoi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">voronoi</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                <span class="s2">&quot;valences&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span><span class="p">,</span>
                <span class="s2">&quot;sites_map&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">sites_map</span><span class="p">,</span>
                <span class="s2">&quot;equivalent_sites&quot;</span><span class="p">:</span> <span class="p">[[</span><span class="n">ps</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">for</span> <span class="n">ps</span> <span class="ow">in</span> <span class="n">psl</span><span class="p">]</span> <span class="k">for</span> <span class="n">psl</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">equivalent_sites</span><span class="p">],</span>
                <span class="s2">&quot;ce_list&quot;</span><span class="p">:</span> <span class="n">ce_list_dict</span><span class="p">,</span>
                <span class="s2">&quot;structure&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                <span class="s2">&quot;neighbors_sets&quot;</span><span class="p">:</span> <span class="n">nbs_sets_dict</span><span class="p">,</span>
                <span class="s2">&quot;info&quot;</span><span class="p">:</span> <span class="n">info_dict</span><span class="p">}</span></div>

<div class="viewcode-block" id="StructureEnvironments.from_dict"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.StructureEnvironments.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reconstructs the StructureEnvironments object from a dict representation of the StructureEnvironments created</span>
<span class="sd">        using the as_dict method.</span>

<span class="sd">        Args:</span>
<span class="sd">            d: dict representation of the StructureEnvironments object.</span>
<span class="sd">        Returns:</span>
<span class="sd">            StructureEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ce_list</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span> <span class="k">if</span> <span class="p">(</span><span class="n">ce_dict</span> <span class="o">==</span> <span class="s1">&#39;None&#39;</span> <span class="ow">or</span> <span class="n">ce_dict</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">)</span> <span class="k">else</span> <span class="p">{</span>
            <span class="nb">int</span><span class="p">(</span><span class="n">cn</span><span class="p">):</span> <span class="p">[</span><span class="kc">None</span> <span class="k">if</span> <span class="p">(</span><span class="n">ced</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">ced</span> <span class="o">==</span> <span class="s1">&#39;None&#39;</span><span class="p">)</span> <span class="k">else</span>
                      <span class="n">ChemicalEnvironments</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">ced</span><span class="p">)</span> <span class="k">for</span> <span class="n">ced</span> <span class="ow">in</span> <span class="n">ce_dict</span><span class="p">[</span><span class="n">cn</span><span class="p">]]</span>
            <span class="k">for</span> <span class="n">cn</span> <span class="ow">in</span> <span class="n">ce_dict</span><span class="p">}</span> <span class="k">for</span> <span class="n">ce_dict</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;ce_list&#39;</span><span class="p">]]</span>
        <span class="n">voronoi</span> <span class="o">=</span> <span class="n">DetailedVoronoiContainer</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;voronoi&#39;</span><span class="p">])</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">])</span>
        <span class="n">neighbors_sets</span> <span class="o">=</span> <span class="p">[{</span><span class="nb">int</span><span class="p">(</span><span class="n">cn</span><span class="p">):</span> <span class="p">[</span><span class="bp">cls</span><span class="o">.</span><span class="n">NeighborsSet</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">dd</span><span class="o">=</span><span class="n">nb_set_dict</span><span class="p">,</span>
                                                                <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span>
                                                                <span class="n">detailed_voronoi</span><span class="o">=</span><span class="n">voronoi</span><span class="p">)</span>
                                     <span class="k">for</span> <span class="n">nb_set_dict</span> <span class="ow">in</span> <span class="n">nb_sets</span><span class="p">]</span>
                           <span class="k">for</span> <span class="n">cn</span><span class="p">,</span> <span class="n">nb_sets</span> <span class="ow">in</span> <span class="n">site_nbs_sets_dict</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
                          <span class="k">if</span> <span class="n">site_nbs_sets_dict</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
                          <span class="k">for</span> <span class="n">site_nbs_sets_dict</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;neighbors_sets&#39;</span><span class="p">]]</span>
        <span class="n">info</span> <span class="o">=</span> <span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="n">val</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;info&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;sites_info&#39;</span><span class="p">]}</span>
        <span class="k">if</span> <span class="s1">&#39;sites_info&#39;</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;info&#39;</span><span class="p">]:</span>
            <span class="n">info</span><span class="p">[</span><span class="s1">&#39;sites_info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;nb_sets_info&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">cn</span><span class="p">):</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">inb_set</span><span class="p">):</span> <span class="n">nb_set_info</span>
                                                              <span class="k">for</span> <span class="n">inb_set</span><span class="p">,</span> <span class="n">nb_set_info</span> <span class="ow">in</span> <span class="n">cn_sets</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
                                                    <span class="k">for</span> <span class="n">cn</span><span class="p">,</span> <span class="n">cn_sets</span> <span class="ow">in</span> <span class="n">site_info</span><span class="p">[</span><span class="s1">&#39;nb_sets_info&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()},</span>
                                   <span class="s1">&#39;time&#39;</span><span class="p">:</span> <span class="n">site_info</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]}</span> <span class="k">if</span> <span class="s1">&#39;nb_sets_info&#39;</span> <span class="ow">in</span> <span class="n">site_info</span> <span class="k">else</span> <span class="p">{}</span>
                                  <span class="k">for</span> <span class="n">site_info</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;info&#39;</span><span class="p">][</span><span class="s1">&#39;sites_info&#39;</span><span class="p">]]</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">voronoi</span><span class="o">=</span><span class="n">voronoi</span><span class="p">,</span> <span class="n">valences</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;valences&#39;</span><span class="p">],</span>
                   <span class="n">sites_map</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;sites_map&#39;</span><span class="p">],</span>
                   <span class="n">equivalent_sites</span><span class="o">=</span><span class="p">[[</span><span class="n">PeriodicSite</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">psd</span><span class="p">)</span> <span class="k">for</span> <span class="n">psd</span> <span class="ow">in</span> <span class="n">psl</span><span class="p">]</span> <span class="k">for</span> <span class="n">psl</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;equivalent_sites&#39;</span><span class="p">]],</span>
                   <span class="n">ce_list</span><span class="o">=</span><span class="n">ce_list</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span>
                   <span class="n">neighbors_sets</span><span class="o">=</span><span class="n">neighbors_sets</span><span class="p">,</span>
                   <span class="n">info</span><span class="o">=</span><span class="n">info</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="LightStructureEnvironments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments">[docs]</a><span class="k">class</span> <span class="nc">LightStructureEnvironments</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class used to store the chemical environments of a given structure obtained from a given ChemenvStrategy. Currently,</span>
<span class="sd">    only strategies leading to the determination of a unique environment for each site is allowed</span>
<span class="sd">    This class does not store all the information contained in the StructureEnvironments object, only the coordination</span>
<span class="sd">    environment found.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">DELTA_MAX_OXIDATION_STATE</span> <span class="o">=</span> <span class="mf">0.1</span>
    <span class="n">DEFAULT_STATISTICS_FIELDS</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;anion_list&#39;</span><span class="p">,</span> <span class="s1">&#39;anion_atom_list&#39;</span><span class="p">,</span> <span class="s1">&#39;cation_list&#39;</span><span class="p">,</span> <span class="s1">&#39;cation_atom_list&#39;</span><span class="p">,</span>
                                 <span class="s1">&#39;neutral_list&#39;</span><span class="p">,</span> <span class="s1">&#39;neutral_atom_list&#39;</span><span class="p">,</span>
                                 <span class="s1">&#39;atom_coordination_environments_present&#39;</span><span class="p">,</span>
                                 <span class="s1">&#39;ion_coordination_environments_present&#39;</span><span class="p">,</span>
                                 <span class="s1">&#39;fraction_atom_coordination_environments_present&#39;</span><span class="p">,</span>
                                 <span class="s1">&#39;fraction_ion_coordination_environments_present&#39;</span><span class="p">,</span>
                                 <span class="s1">&#39;coordination_environments_atom_present&#39;</span><span class="p">,</span>
                                 <span class="s1">&#39;coordination_environments_ion_present&#39;</span><span class="p">]</span>

<div class="viewcode-block" id="LightStructureEnvironments.NeighborsSet"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.NeighborsSet">[docs]</a>    <span class="k">class</span> <span class="nc">NeighborsSet</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Class used to store a given set of neighbors of a given site (based on a list of sites, the voronoi</span>
<span class="sd">        container is not part of the LightStructureEnvironments object).</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">all_nbs_sites</span><span class="p">,</span> <span class="n">all_nbs_sites_indices</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Constructor for NeighborsSet.</span>

<span class="sd">            Args:</span>
<span class="sd">                structure: Structure object.</span>
<span class="sd">                isite: Index of the site for which neighbors are stored in this NeighborsSet.</span>
<span class="sd">                all_nbs_sites: All the possible neighbors for this site.</span>
<span class="sd">                all_nbs_sites_indices: Indices of the sites in all_nbs_sites that make up this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">isite</span> <span class="o">=</span> <span class="n">isite</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites</span> <span class="o">=</span> <span class="n">all_nbs_sites</span>
            <span class="n">myset</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">all_nbs_sites_indices</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">myset</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">all_nbs_sites_indices</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Set of neighbors contains duplicates !&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">myset</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices_unsorted</span> <span class="o">=</span> <span class="n">all_nbs_sites_indices</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices_and_image</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">neighb_coords</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Coordinates of neighbors for this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;site&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">coords</span> <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices_unsorted</span><span class="p">]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">neighb_sites</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Neighbors for this NeighborsSet as pymatgen Sites.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;site&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices_unsorted</span><span class="p">]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">neighb_sites_and_indices</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            List of neighbors for this NeighborsSet as pymatgen Sites and their index in the original structure.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[{</span><span class="s1">&#39;site&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;site&#39;</span><span class="p">],</span>
                     <span class="s1">&#39;index&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;index&#39;</span><span class="p">]}</span> <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices_unsorted</span><span class="p">]</span>

        <span class="nd">@property</span>
        <span class="k">def</span> <span class="nf">neighb_indices_and_images</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            List of indices and images with respect to the original unit cell sites for this NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">[{</span><span class="s1">&#39;index&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;index&#39;</span><span class="p">],</span>
                     <span class="s1">&#39;image_cell&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites</span><span class="p">[</span><span class="n">inb</span><span class="p">][</span><span class="s1">&#39;image_cell&#39;</span><span class="p">]}</span>
                    <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices_unsorted</span><span class="p">]</span>

        <span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices</span><span class="p">)</span>

        <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices</span><span class="p">)</span>

        <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">isite</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">isite</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">all_nbs_sites_indices</span>

        <span class="k">def</span> <span class="fm">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
            <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span> <span class="o">==</span> <span class="n">other</span>

        <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="n">out</span> <span class="o">=</span> <span class="s1">&#39;Neighbors Set for site #</span><span class="si">{:d}</span><span class="s1"> :</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">isite</span><span class="p">)</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39; - Coordination number : </span><span class="si">{:d}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39; - Neighbors sites indices : </span><span class="si">{}</span><span class="s1">&#39;</span> \
                   <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s1">&#39;</span><span class="si">{:d}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">nb_list_index</span><span class="p">)</span>
                                          <span class="k">for</span> <span class="n">nb_list_index</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices</span><span class="p">]))</span>
            <span class="k">return</span> <span class="n">out</span>

<div class="viewcode-block" id="LightStructureEnvironments.NeighborsSet.as_dict"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.NeighborsSet.as_dict">[docs]</a>        <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            A JSON serializable dict representation of the NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;isite&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">isite</span><span class="p">,</span>
                    <span class="s1">&#39;all_nbs_sites_indices&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_nbs_sites_indices_unsorted</span><span class="p">}</span></div>
            <span class="c1"># &#39;all_nbs_sites_indices_unsorted&#39;: self.all_nbs_sites_indices_unsorted}</span>

<div class="viewcode-block" id="LightStructureEnvironments.NeighborsSet.from_dict"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.NeighborsSet.from_dict">[docs]</a>        <span class="nd">@classmethod</span>
        <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">dd</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">all_nbs_sites</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Reconstructs the NeighborsSet algorithm from its JSON serializable dict representation, together with</span>
<span class="sd">            the structure and all the possible neighbors sites.</span>

<span class="sd">            As an inner (nested) class, the NeighborsSet is not supposed to be used anywhere else that inside the</span>
<span class="sd">            LightStructureEnvironments. The from_dict method is thus using the structure and all_nbs_sites when</span>
<span class="sd">            reconstructing itself. These two are both in the LightStructureEnvironments object.</span>

<span class="sd">            Args:</span>
<span class="sd">                dd: a JSON serializable dict representation of a NeighborsSet.</span>
<span class="sd">                structure: The structure.</span>
<span class="sd">                all_nbs_sites: The list of all the possible neighbors for a given site.</span>

<span class="sd">            Returns: a NeighborsSet.</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span>
                       <span class="n">isite</span><span class="o">=</span><span class="n">dd</span><span class="p">[</span><span class="s1">&#39;isite&#39;</span><span class="p">],</span>
                       <span class="n">all_nbs_sites</span><span class="o">=</span><span class="n">all_nbs_sites</span><span class="p">,</span>
                       <span class="n">all_nbs_sites_indices</span><span class="o">=</span><span class="n">dd</span><span class="p">[</span><span class="s1">&#39;all_nbs_sites_indices&#39;</span><span class="p">])</span></div></div>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">strategy</span><span class="p">,</span>
                 <span class="n">coordination_environments</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">all_nbs_sites</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">neighbors_sets</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">structure</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">valences</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">valences_origin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor for the LightStructureEnvironments object.</span>

<span class="sd">        Args:</span>
<span class="sd">            strategy: ChemEnv strategy used to get the environments.</span>
<span class="sd">            coordination_environments: The coordination environments identified.</span>
<span class="sd">            all_nbs_sites: All the possible neighbors for each site in the structure.</span>
<span class="sd">            neighbors_sets: The neighbors sets of each site in the structure.</span>
<span class="sd">            structure: The structure.</span>
<span class="sd">            valences: The valences used to get the environments (if needed).</span>
<span class="sd">            valences_origin: How the valences were obtained (e.g. from the Bond-valence analysis or from the original</span>
<span class="sd">                structure).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">strategy</span> <span class="o">=</span> <span class="n">strategy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span> <span class="o">=</span> <span class="n">coordination_environments</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_all_nbs_sites</span> <span class="o">=</span> <span class="n">all_nbs_sites</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span> <span class="o">=</span> <span class="n">neighbors_sets</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">=</span> <span class="n">valences</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">valences_origin</span> <span class="o">=</span> <span class="n">valences_origin</span>

<div class="viewcode-block" id="LightStructureEnvironments.from_structure_environments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.from_structure_environments">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_structure_environments</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">strategy</span><span class="p">,</span> <span class="n">structure_environments</span><span class="p">,</span> <span class="n">valences</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">valences_origin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Construct a LightStructureEnvironments object from a strategy and a StructureEnvironments object.</span>

<span class="sd">        Args:</span>
<span class="sd">            strategy: ChemEnv strategy used.</span>
<span class="sd">            structure_environments: StructureEnvironments object from which to construct the LightStructureEnvironments.</span>
<span class="sd">            valences: The valences of each site in the structure.</span>
<span class="sd">            valences_origin: How the valences were obtained (e.g. from the Bond-valence analysis or from the original</span>
<span class="sd">                structure).</span>

<span class="sd">        Returns: a LightStructureEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="n">structure_environments</span><span class="o">.</span><span class="n">structure</span>
        <span class="n">strategy</span><span class="o">.</span><span class="n">set_structure_environments</span><span class="p">(</span><span class="n">structure_environments</span><span class="o">=</span><span class="n">structure_environments</span><span class="p">)</span>
        <span class="n">coordination_environments</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
        <span class="n">neighbors_sets</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
        <span class="n">_all_nbs_sites</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">my_all_nbs_sites</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">valences</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">valences</span> <span class="o">=</span> <span class="n">structure_environments</span><span class="o">.</span><span class="n">valences</span>
            <span class="k">if</span> <span class="n">valences_origin</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">valences_origin</span> <span class="o">=</span> <span class="s1">&#39;from_structure_environments&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">valences_origin</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">valences_origin</span> <span class="o">=</span> <span class="s1">&#39;user-specified&#39;</span>

        <span class="k">for</span> <span class="n">isite</span><span class="p">,</span> <span class="n">site</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">structure</span><span class="p">):</span>
            <span class="n">site_ces_and_nbs_list</span> <span class="o">=</span> <span class="n">strategy</span><span class="o">.</span><span class="n">get_site_ce_fractions_and_neighbors</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">strategy_info</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">site_ces_and_nbs_list</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">site_ces</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">site_nbs_sets</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">ce_and_neighbors</span> <span class="ow">in</span> <span class="n">site_ces_and_nbs_list</span><span class="p">:</span>
                <span class="n">_all_nbs_sites_indices</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="c1"># Coordination environment</span>
                <span class="n">ce_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">:</span> <span class="n">ce_and_neighbors</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">],</span>
                           <span class="s1">&#39;ce_fraction&#39;</span><span class="p">:</span> <span class="n">ce_and_neighbors</span><span class="p">[</span><span class="s1">&#39;ce_fraction&#39;</span><span class="p">]}</span>
                <span class="k">if</span> <span class="n">ce_and_neighbors</span><span class="p">[</span><span class="s1">&#39;ce_dict&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">csm</span> <span class="o">=</span> <span class="n">ce_and_neighbors</span><span class="p">[</span><span class="s1">&#39;ce_dict&#39;</span><span class="p">][</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">][</span><span class="n">strategy</span><span class="o">.</span><span class="n">symmetry_measure_type</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">csm</span> <span class="o">=</span> <span class="kc">None</span>
                <span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;csm&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">csm</span>
                <span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;permutation&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ce_and_neighbors</span><span class="p">[</span><span class="s1">&#39;ce_dict&#39;</span><span class="p">][</span><span class="s1">&#39;permutation&#39;</span><span class="p">]</span>
                <span class="n">site_ces</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ce_dict</span><span class="p">)</span>
                <span class="c1"># Neighbors</span>
                <span class="n">neighbors</span> <span class="o">=</span> <span class="n">ce_and_neighbors</span><span class="p">[</span><span class="s1">&#39;neighbors&#39;</span><span class="p">]</span>
                <span class="k">for</span> <span class="n">nb_site_and_index</span> <span class="ow">in</span> <span class="n">neighbors</span><span class="p">:</span>
                    <span class="n">nb_site</span> <span class="o">=</span> <span class="n">nb_site_and_index</span><span class="p">[</span><span class="s1">&#39;site&#39;</span><span class="p">]</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">nb_allnbs_sites_index</span> <span class="o">=</span> <span class="n">my_all_nbs_sites</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">nb_site</span><span class="p">)</span>
                    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                        <span class="n">nb_index_unitcell</span> <span class="o">=</span> <span class="n">nb_site_and_index</span><span class="p">[</span><span class="s1">&#39;index&#39;</span><span class="p">]</span>
                        <span class="n">diff</span> <span class="o">=</span> <span class="n">nb_site</span><span class="o">.</span><span class="n">frac_coords</span> <span class="o">-</span> <span class="n">structure</span><span class="p">[</span><span class="n">nb_index_unitcell</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span>
                        <span class="n">rounddiff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">diff</span><span class="p">)</span>
                        <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="n">rounddiff</span><span class="p">):</span>
                            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Weird, differences between one site in a periodic image cell is not &#39;</span>
                                             <span class="s1">&#39;integer ...&#39;</span><span class="p">)</span>
                        <span class="n">nb_image_cell</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">rounddiff</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
                        <span class="n">nb_allnbs_sites_index</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">_all_nbs_sites</span><span class="p">)</span>
                        <span class="n">_all_nbs_sites</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;site&#39;</span><span class="p">:</span> <span class="n">nb_site</span><span class="p">,</span>
                                               <span class="s1">&#39;index&#39;</span><span class="p">:</span> <span class="n">nb_index_unitcell</span><span class="p">,</span>
                                               <span class="s1">&#39;image_cell&#39;</span><span class="p">:</span> <span class="n">nb_image_cell</span><span class="p">})</span>
                        <span class="n">my_all_nbs_sites</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nb_site</span><span class="p">)</span>
                    <span class="n">_all_nbs_sites_indices</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nb_allnbs_sites_index</span><span class="p">)</span>

                <span class="n">nb_set</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">NeighborsSet</span><span class="p">(</span><span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span>
                                          <span class="n">all_nbs_sites</span><span class="o">=</span><span class="n">_all_nbs_sites</span><span class="p">,</span>
                                          <span class="n">all_nbs_sites_indices</span><span class="o">=</span><span class="n">_all_nbs_sites_indices</span><span class="p">)</span>
                <span class="n">site_nbs_sets</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nb_set</span><span class="p">)</span>
            <span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="o">=</span> <span class="n">site_ces</span>
            <span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="o">=</span> <span class="n">site_nbs_sets</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">strategy</span><span class="o">=</span><span class="n">strategy</span><span class="p">,</span>
                   <span class="n">coordination_environments</span><span class="o">=</span><span class="n">coordination_environments</span><span class="p">,</span>
                   <span class="n">all_nbs_sites</span><span class="o">=</span><span class="n">_all_nbs_sites</span><span class="p">,</span>
                   <span class="n">neighbors_sets</span><span class="o">=</span><span class="n">neighbors_sets</span><span class="p">,</span>
                   <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">valences</span><span class="o">=</span><span class="n">valences</span><span class="p">,</span>
                   <span class="n">valences_origin</span><span class="o">=</span><span class="n">valences_origin</span><span class="p">)</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.setup_statistic_lists"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.setup_statistic_lists">[docs]</a>    <span class="k">def</span> <span class="nf">setup_statistic_lists</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set up the statistics of environments for this LightStructureEnvironments.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;valences_origin&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences_origin</span><span class="p">,</span>
                                <span class="s1">&#39;anion_list&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;anion_number&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;anion_atom_list&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;anion_atom_number&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;cation_list&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;cation_number&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;cation_atom_list&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;cation_atom_number&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;neutral_list&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;neutral_number&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;neutral_atom_list&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;neutral_atom_number&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;atom_coordination_environments_present&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;ion_coordination_environments_present&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;coordination_environments_ion_present&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;coordination_environments_atom_present&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;fraction_ion_coordination_environments_present&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;fraction_atom_coordination_environments_present&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;fraction_coordination_environments_ion_present&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;fraction_coordination_environments_atom_present&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;count_ion_present&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;count_atom_present&#39;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># OK</span>
                                <span class="s1">&#39;count_coordination_environments_present&#39;</span><span class="p">:</span> <span class="p">{}}</span>
        <span class="n">atom_stat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;atom_coordination_environments_present&#39;</span><span class="p">]</span>
        <span class="n">ce_atom_stat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;coordination_environments_atom_present&#39;</span><span class="p">]</span>
        <span class="n">fraction_atom_stat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;fraction_atom_coordination_environments_present&#39;</span><span class="p">]</span>
        <span class="n">fraction_ce_atom_stat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;fraction_coordination_environments_atom_present&#39;</span><span class="p">]</span>
        <span class="n">count_atoms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;count_atom_present&#39;</span><span class="p">]</span>
        <span class="n">count_ce</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;count_coordination_environments_present&#39;</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">isite</span><span class="p">,</span> <span class="n">site</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">):</span>
            <span class="c1"># Building anion and cation list</span>
            <span class="n">site_species</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">!=</span> <span class="s1">&#39;undefined&#39;</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">sp</span><span class="p">,</span> <span class="n">occ</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">valence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span>
                    <span class="n">strspecie</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">Specie</span><span class="p">(</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="n">valence</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">valence</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">specielist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;anion_list&#39;</span><span class="p">]</span>
                        <span class="n">atomlist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;anion_atom_list&#39;</span><span class="p">]</span>
                    <span class="k">elif</span> <span class="n">valence</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">specielist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;cation_list&#39;</span><span class="p">]</span>
                        <span class="n">atomlist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;cation_atom_list&#39;</span><span class="p">]</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">specielist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;neutral_list&#39;</span><span class="p">]</span>
                        <span class="n">atomlist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;neutral_atom_list&#39;</span><span class="p">]</span>
                    <span class="k">if</span> <span class="n">strspecie</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">specielist</span><span class="p">:</span>
                        <span class="n">specielist</span><span class="p">[</span><span class="n">strspecie</span><span class="p">]</span> <span class="o">=</span> <span class="n">occ</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">specielist</span><span class="p">[</span><span class="n">strspecie</span><span class="p">]</span> <span class="o">+=</span> <span class="n">occ</span>
                    <span class="k">if</span> <span class="n">sp</span><span class="o">.</span><span class="n">symbol</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">atomlist</span><span class="p">:</span>
                        <span class="n">atomlist</span><span class="p">[</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span><span class="p">]</span> <span class="o">=</span> <span class="n">occ</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">atomlist</span><span class="p">[</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span><span class="p">]</span> <span class="o">+=</span> <span class="n">occ</span>
                    <span class="n">site_species</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="n">valence</span><span class="p">,</span> <span class="n">occ</span><span class="p">))</span>
            <span class="c1"># Building environments lists</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">site_envs</span> <span class="o">=</span> <span class="p">[(</span><span class="n">ce_piece_dict</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">],</span> <span class="n">ce_piece_dict</span><span class="p">[</span><span class="s1">&#39;ce_fraction&#39;</span><span class="p">])</span>
                             <span class="k">for</span> <span class="n">ce_piece_dict</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]]</span>
                <span class="k">for</span> <span class="n">ce_symbol</span><span class="p">,</span> <span class="n">fraction</span> <span class="ow">in</span> <span class="n">site_envs</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">fraction</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="k">continue</span>
                    <span class="k">if</span> <span class="n">ce_symbol</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">count_ce</span><span class="p">:</span>
                        <span class="n">count_ce</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="n">count_ce</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">]</span> <span class="o">+=</span> <span class="n">fraction</span>
                <span class="k">for</span> <span class="n">sp</span><span class="p">,</span> <span class="n">occ</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">elmt</span> <span class="o">=</span> <span class="n">sp</span><span class="o">.</span><span class="n">symbol</span>
                    <span class="k">if</span> <span class="n">elmt</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">atom_stat</span><span class="p">:</span>
                        <span class="n">atom_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                        <span class="n">count_atoms</span><span class="p">[</span><span class="n">elmt</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="n">count_atoms</span><span class="p">[</span><span class="n">elmt</span><span class="p">]</span> <span class="o">+=</span> <span class="n">occ</span>
                    <span class="k">for</span> <span class="n">ce_symbol</span><span class="p">,</span> <span class="n">fraction</span> <span class="ow">in</span> <span class="n">site_envs</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">fraction</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                            <span class="k">continue</span>
                        <span class="k">if</span> <span class="n">ce_symbol</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">atom_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">]:</span>
                            <span class="n">atom_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">][</span><span class="n">ce_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>

                        <span class="n">atom_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">][</span><span class="n">ce_symbol</span><span class="p">]</span> <span class="o">+=</span> <span class="n">occ</span> <span class="o">*</span> <span class="n">fraction</span>
                        <span class="k">if</span> <span class="n">ce_symbol</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ce_atom_stat</span><span class="p">:</span>
                            <span class="n">ce_atom_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                        <span class="k">if</span> <span class="n">elmt</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ce_atom_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">]:</span>
                            <span class="n">ce_atom_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">][</span><span class="n">elmt</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>
                        <span class="n">ce_atom_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">][</span><span class="n">elmt</span><span class="p">]</span> <span class="o">+=</span> <span class="n">occ</span> <span class="o">*</span> <span class="n">fraction</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">!=</span> <span class="s1">&#39;undefined&#39;</span><span class="p">:</span>
                    <span class="n">ion_stat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;ion_coordination_environments_present&#39;</span><span class="p">]</span>
                    <span class="n">ce_ion_stat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;coordination_environments_ion_present&#39;</span><span class="p">]</span>
                    <span class="n">count_ions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;count_ion_present&#39;</span><span class="p">]</span>
                    <span class="k">for</span> <span class="n">elmt</span><span class="p">,</span> <span class="n">oxi_state</span><span class="p">,</span> <span class="n">occ</span> <span class="ow">in</span> <span class="n">site_species</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">elmt</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ion_stat</span><span class="p">:</span>
                            <span class="n">ion_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                            <span class="n">count_ions</span><span class="p">[</span><span class="n">elmt</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                        <span class="k">if</span> <span class="n">oxi_state</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ion_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">]:</span>
                            <span class="n">ion_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">][</span><span class="n">oxi_state</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                            <span class="n">count_ions</span><span class="p">[</span><span class="n">elmt</span><span class="p">][</span><span class="n">oxi_state</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>
                        <span class="n">count_ions</span><span class="p">[</span><span class="n">elmt</span><span class="p">][</span><span class="n">oxi_state</span><span class="p">]</span> <span class="o">+=</span> <span class="n">occ</span>
                        <span class="k">for</span> <span class="n">ce_symbol</span><span class="p">,</span> <span class="n">fraction</span> <span class="ow">in</span> <span class="n">site_envs</span><span class="p">:</span>
                            <span class="k">if</span> <span class="n">fraction</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                                <span class="k">continue</span>
                            <span class="k">if</span> <span class="n">ce_symbol</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ion_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">][</span><span class="n">oxi_state</span><span class="p">]:</span>
                                <span class="n">ion_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">][</span><span class="n">oxi_state</span><span class="p">][</span><span class="n">ce_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>
                            <span class="n">ion_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">][</span><span class="n">oxi_state</span><span class="p">][</span><span class="n">ce_symbol</span><span class="p">]</span> <span class="o">+=</span> <span class="n">occ</span> <span class="o">*</span> <span class="n">fraction</span>
                            <span class="k">if</span> <span class="n">ce_symbol</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ce_ion_stat</span><span class="p">:</span>
                                <span class="n">ce_ion_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                            <span class="k">if</span> <span class="n">elmt</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ce_ion_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">]:</span>
                                <span class="n">ce_ion_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">][</span><span class="n">elmt</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                            <span class="k">if</span> <span class="n">oxi_state</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ce_ion_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">][</span><span class="n">elmt</span><span class="p">]:</span>
                                <span class="n">ce_ion_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">][</span><span class="n">elmt</span><span class="p">][</span><span class="n">oxi_state</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>
                            <span class="n">ce_ion_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">][</span><span class="n">elmt</span><span class="p">][</span><span class="n">oxi_state</span><span class="p">]</span> <span class="o">+=</span> <span class="n">occ</span> <span class="o">*</span> <span class="n">fraction</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;anion_number&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;anion_list&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;anion_atom_number&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;anion_atom_list&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;cation_number&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;cation_list&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;cation_atom_number&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;cation_atom_list&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;neutral_number&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;neutral_list&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;neutral_atom_number&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;neutral_atom_list&#39;</span><span class="p">])</span>

        <span class="k">for</span> <span class="n">elmt</span><span class="p">,</span> <span class="n">envs</span> <span class="ow">in</span> <span class="n">atom_stat</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">sumelement</span> <span class="o">=</span> <span class="n">count_atoms</span><span class="p">[</span><span class="n">elmt</span><span class="p">]</span>
            <span class="n">fraction_atom_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">env</span><span class="p">:</span> <span class="n">fraction</span> <span class="o">/</span> <span class="n">sumelement</span> <span class="k">for</span> <span class="n">env</span><span class="p">,</span> <span class="n">fraction</span> <span class="ow">in</span> <span class="n">envs</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">for</span> <span class="n">ce_symbol</span><span class="p">,</span> <span class="n">atoms</span> <span class="ow">in</span> <span class="n">ce_atom_stat</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">sumsymbol</span> <span class="o">=</span> <span class="n">count_ce</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">]</span>
            <span class="n">fraction_ce_atom_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">atom</span><span class="p">:</span> <span class="n">fraction</span> <span class="o">/</span> <span class="n">sumsymbol</span> <span class="k">for</span> <span class="n">atom</span><span class="p">,</span> <span class="n">fraction</span> <span class="ow">in</span> <span class="n">atoms</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">ion_stat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;ion_coordination_environments_present&#39;</span><span class="p">]</span>
        <span class="n">fraction_ion_stat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;fraction_ion_coordination_environments_present&#39;</span><span class="p">]</span>
        <span class="n">ce_ion_stat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;coordination_environments_ion_present&#39;</span><span class="p">]</span>
        <span class="n">fraction_ce_ion_stat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;fraction_coordination_environments_ion_present&#39;</span><span class="p">]</span>
        <span class="n">count_ions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;count_ion_present&#39;</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">elmt</span><span class="p">,</span> <span class="n">oxi_states_envs</span> <span class="ow">in</span> <span class="n">ion_stat</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">fraction_ion_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">oxi_state</span><span class="p">,</span> <span class="n">envs</span> <span class="ow">in</span> <span class="n">oxi_states_envs</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">sumspecie</span> <span class="o">=</span> <span class="n">count_ions</span><span class="p">[</span><span class="n">elmt</span><span class="p">][</span><span class="n">oxi_state</span><span class="p">]</span>
                <span class="n">fraction_ion_stat</span><span class="p">[</span><span class="n">elmt</span><span class="p">][</span><span class="n">oxi_state</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">env</span><span class="p">:</span> <span class="n">fraction</span> <span class="o">/</span> <span class="n">sumspecie</span>
                                                      <span class="k">for</span> <span class="n">env</span><span class="p">,</span> <span class="n">fraction</span> <span class="ow">in</span> <span class="n">envs</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">for</span> <span class="n">ce_symbol</span><span class="p">,</span> <span class="n">ions</span> <span class="ow">in</span> <span class="n">ce_ion_stat</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">fraction_ce_ion_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="n">sum_ce</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">oxistates</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span> <span class="k">for</span> <span class="n">elmt</span><span class="p">,</span> <span class="n">oxistates</span> <span class="ow">in</span> <span class="n">ions</span><span class="o">.</span><span class="n">items</span><span class="p">()])</span>
            <span class="k">for</span> <span class="n">elmt</span><span class="p">,</span> <span class="n">oxistates</span> <span class="ow">in</span> <span class="n">ions</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">fraction_ce_ion_stat</span><span class="p">[</span><span class="n">ce_symbol</span><span class="p">][</span><span class="n">elmt</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">oxistate</span><span class="p">:</span> <span class="n">fraction</span> <span class="o">/</span> <span class="n">sum_ce</span>
                                                         <span class="k">for</span> <span class="n">oxistate</span><span class="p">,</span> <span class="n">fraction</span> <span class="ow">in</span> <span class="n">oxistates</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.get_site_info_for_specie_ce"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.get_site_info_for_specie_ce">[docs]</a>    <span class="k">def</span> <span class="nf">get_site_info_for_specie_ce</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">specie</span><span class="p">,</span> <span class="n">ce_symbol</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get list of indices that have the given specie with a given Coordination environment.</span>

<span class="sd">        Args:</span>
<span class="sd">            specie: Specie to get.</span>
<span class="sd">            ce_symbol: Symbol of the coordination environment to get.</span>

<span class="sd">        Returns: Dictionary with the list of indices in the structure that have the given specie in the given</span>
<span class="sd">            environment, their fraction and continuous symmetry measures.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">element</span> <span class="o">=</span> <span class="n">specie</span><span class="o">.</span><span class="n">symbol</span>
        <span class="n">oxi_state</span> <span class="o">=</span> <span class="n">specie</span><span class="o">.</span><span class="n">oxi_state</span>
        <span class="n">isites</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">csms</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">fractions</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">isite</span><span class="p">,</span> <span class="n">site</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">element</span> <span class="ow">in</span> <span class="p">[</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">sp</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="p">]:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">==</span> <span class="s1">&#39;undefined&#39;</span> <span class="ow">or</span> <span class="n">oxi_state</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span><span class="p">[</span><span class="n">isite</span><span class="p">]:</span>
                    <span class="k">for</span> <span class="n">ce_dict</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]:</span>
                        <span class="k">if</span> <span class="n">ce_symbol</span> <span class="o">==</span> <span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">]:</span>
                            <span class="n">isites</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">isite</span><span class="p">)</span>
                            <span class="n">csms</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;csm&#39;</span><span class="p">])</span>
                            <span class="n">fractions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;ce_fraction&#39;</span><span class="p">])</span>
        <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;isites&#39;</span><span class="p">:</span> <span class="n">isites</span><span class="p">,</span> <span class="s1">&#39;fractions&#39;</span><span class="p">:</span> <span class="n">fractions</span><span class="p">,</span> <span class="s1">&#39;csms&#39;</span><span class="p">:</span> <span class="n">csms</span><span class="p">}</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.get_site_info_for_specie_allces"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.get_site_info_for_specie_allces">[docs]</a>    <span class="k">def</span> <span class="nf">get_site_info_for_specie_allces</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">specie</span><span class="p">,</span> <span class="n">min_fraction</span><span class="o">=</span><span class="mf">0.0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get list of indices that have the given specie.</span>

<span class="sd">        Args:</span>
<span class="sd">            specie: Specie to get.</span>

<span class="sd">        Returns: Dictionary with the list of coordination environments for the given species, the indices of the sites</span>
<span class="sd">            in which they appear, their fractions and continuous symmetry measures.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">allces</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">element</span> <span class="o">=</span> <span class="n">specie</span><span class="o">.</span><span class="n">symbol</span>
        <span class="n">oxi_state</span> <span class="o">=</span> <span class="n">specie</span><span class="o">.</span><span class="n">oxi_state</span>
        <span class="k">for</span> <span class="n">isite</span><span class="p">,</span> <span class="n">site</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">element</span> <span class="ow">in</span> <span class="p">[</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">sp</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="p">]:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">==</span> <span class="s1">&#39;undefined&#39;</span> <span class="ow">or</span> <span class="n">oxi_state</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span><span class="p">[</span><span class="n">isite</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="k">continue</span>
                    <span class="k">for</span> <span class="n">ce_dict</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]:</span>
                        <span class="k">if</span> <span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;ce_fraction&#39;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">min_fraction</span><span class="p">:</span>
                            <span class="k">continue</span>
                        <span class="k">if</span> <span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">allces</span><span class="p">:</span>
                            <span class="n">allces</span><span class="p">[</span><span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;isites&#39;</span><span class="p">:</span> <span class="p">[],</span> <span class="s1">&#39;fractions&#39;</span><span class="p">:</span> <span class="p">[],</span> <span class="s1">&#39;csms&#39;</span><span class="p">:</span> <span class="p">[]}</span>
                        <span class="n">allces</span><span class="p">[</span><span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">]][</span><span class="s1">&#39;isites&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">isite</span><span class="p">)</span>
                        <span class="n">allces</span><span class="p">[</span><span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">]][</span><span class="s1">&#39;fractions&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;ce_fraction&#39;</span><span class="p">])</span>
                        <span class="n">allces</span><span class="p">[</span><span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">]][</span><span class="s1">&#39;csms&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;csm&#39;</span><span class="p">])</span>
        <span class="k">return</span> <span class="n">allces</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.get_statistics"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.get_statistics">[docs]</a>    <span class="k">def</span> <span class="nf">get_statistics</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">statistics_fields</span><span class="o">=</span><span class="n">DEFAULT_STATISTICS_FIELDS</span><span class="p">,</span> <span class="n">bson_compatible</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the statistics of environments for this structure.</span>
<span class="sd">        Args:</span>
<span class="sd">            statistics_fields: Which statistics to get.</span>
<span class="sd">            bson_compatible: Whether to make the dictionary BSON-compatible.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A dictionary with the requested statistics.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">setup_statistic_lists</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">statistics_fields</span> <span class="o">==</span> <span class="s1">&#39;ALL&#39;</span><span class="p">:</span>
            <span class="n">statistics_fields</span> <span class="o">=</span> <span class="p">[</span><span class="n">key</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">bson_compatible</span><span class="p">:</span>
            <span class="n">dd</span> <span class="o">=</span> <span class="n">jsanitize</span><span class="p">({</span><span class="n">field</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="n">field</span><span class="p">]</span> <span class="k">for</span> <span class="n">field</span> <span class="ow">in</span> <span class="n">statistics_fields</span><span class="p">})</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">dd</span> <span class="o">=</span> <span class="p">{</span><span class="n">field</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="n">field</span><span class="p">]</span> <span class="k">for</span> <span class="n">field</span> <span class="ow">in</span> <span class="n">statistics_fields</span><span class="p">}</span>
        <span class="k">return</span> <span class="n">dd</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.contains_only_one_anion_atom"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.contains_only_one_anion_atom">[docs]</a>    <span class="k">def</span> <span class="nf">contains_only_one_anion_atom</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">anion_atom</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Whether this LightStructureEnvironments concerns a structure with only one given anion atom type.</span>

<span class="sd">        Args:</span>
<span class="sd">            anion_atom: Anion (e.g. O, ...). The structure could contain O2- and O- though.</span>

<span class="sd">        Returns: True if this LightStructureEnvironments concerns a structure with only one given anion_atom.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;anion_atom_list&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span>
                <span class="n">anion_atom</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;anion_atom_list&#39;</span><span class="p">])</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.contains_only_one_anion"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.contains_only_one_anion">[docs]</a>    <span class="k">def</span> <span class="nf">contains_only_one_anion</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">anion</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Whether this LightStructureEnvironments concerns a structure with only one given anion type.</span>

<span class="sd">        Args:</span>
<span class="sd">            anion: Anion (e.g. O2-, ...).</span>

<span class="sd">        Returns: True if this LightStructureEnvironments concerns a structure with only one given anion.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;anion_list&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">anion</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics_dict</span><span class="p">[</span><span class="s1">&#39;anion_list&#39;</span><span class="p">]</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.site_contains_environment"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.site_contains_environment">[docs]</a>    <span class="k">def</span> <span class="nf">site_contains_environment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">ce_symbol</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Whether a given site contains a given coordination environment.</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site.</span>
<span class="sd">            ce_symbol: Symbol of the coordination environment.</span>

<span class="sd">        Returns: True if the site contains the given coordination environment.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="n">ce_symbol</span> <span class="ow">in</span> <span class="p">[</span><span class="n">ce_dict</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">ce_dict</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]]</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.site_has_clear_environment"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.site_has_clear_environment">[docs]</a>    <span class="k">def</span> <span class="nf">site_has_clear_environment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">conditions</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Whether a given site has a &quot;clear&quot; environments.</span>

<span class="sd">        A &quot;clear&quot; environment is somewhat arbitrary. You can pass (multiple) conditions, e.g. the environment should</span>
<span class="sd">        have a continuous symmetry measure lower than this, a fraction higher than that, ...</span>

<span class="sd">        Args:</span>
<span class="sd">            isite: Index of the site.</span>
<span class="sd">            conditions: Conditions to be checked for an environment to be &quot;clear&quot;.</span>

<span class="sd">        Returns: True if the site has a clear environment.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Coordination environments have not been determined for site </span><span class="si">{:d}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">isite</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">conditions</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">])</span> <span class="o">==</span> <span class="mi">1</span>
        <span class="n">ce</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">],</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="s1">&#39;ce_fraction&#39;</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">condition</span> <span class="ow">in</span> <span class="n">conditions</span><span class="p">:</span>
            <span class="n">target</span> <span class="o">=</span> <span class="n">condition</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s1">&#39;ce_fraction&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">ce</span><span class="p">[</span><span class="n">target</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">condition</span><span class="p">[</span><span class="s1">&#39;minvalue&#39;</span><span class="p">]:</span>
                    <span class="k">return</span> <span class="kc">False</span>
            <span class="k">elif</span> <span class="n">target</span> <span class="o">==</span> <span class="s1">&#39;csm&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">ce</span><span class="p">[</span><span class="n">target</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">condition</span><span class="p">[</span><span class="s1">&#39;maxvalue&#39;</span><span class="p">]:</span>
                    <span class="k">return</span> <span class="kc">False</span>
            <span class="k">elif</span> <span class="n">target</span> <span class="o">==</span> <span class="s1">&#39;number_of_ces&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">ce</span><span class="p">[</span><span class="n">target</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">condition</span><span class="p">[</span><span class="s1">&#39;maxnumber&#39;</span><span class="p">]:</span>
                    <span class="k">return</span> <span class="kc">False</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Target &quot;</span><span class="si">{}</span><span class="s1">&quot; for condition of clear environment is not allowed&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">target</span><span class="p">))</span>
        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.structure_has_clear_environments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.structure_has_clear_environments">[docs]</a>    <span class="k">def</span> <span class="nf">structure_has_clear_environments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">conditions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">skip_none</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">skip_empty</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Whether all sites in a structure have &quot;clear&quot; environments.</span>
<span class="sd">        Args:</span>
<span class="sd">            conditions: Conditions to be checked for an environment to be &quot;clear&quot;.</span>
<span class="sd">            skip_none: Whether to skip sites for which no environments have been computed.</span>
<span class="sd">            skip_empty: Whether to skip sites for which no environments could be found.</span>

<span class="sd">        Returns: True if all the sites in the structure have clear environments.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">isite</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">skip_none</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">return</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">skip_empty</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">return</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_has_clear_environment</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">conditions</span><span class="o">=</span><span class="n">conditions</span><span class="p">):</span>
                <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.clear_environments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.clear_environments">[docs]</a>    <span class="k">def</span> <span class="nf">clear_environments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">conditions</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the clear environments in the structure.</span>

<span class="sd">        Args:</span>
<span class="sd">            conditions: Conditions to be checked for an environment to be &quot;clear&quot;.</span>

<span class="sd">        Returns: Set of clear environments in this structure.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">clear_envs_list</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">isite</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_has_clear_environment</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">conditions</span><span class="o">=</span><span class="n">conditions</span><span class="p">):</span>
                <span class="n">ce</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">[</span><span class="n">isite</span><span class="p">],</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="s1">&#39;ce_fraction&#39;</span><span class="p">])</span>
                <span class="n">clear_envs_list</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">ce</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">])</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">clear_envs_list</span><span class="p">)</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.structure_contains_atom_environment"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.structure_contains_atom_environment">[docs]</a>    <span class="k">def</span> <span class="nf">structure_contains_atom_environment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">atom_symbol</span><span class="p">,</span> <span class="n">ce_symbol</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Checks whether the structure contains a given atom in a given environment.</span>

<span class="sd">        Args:</span>
<span class="sd">            atom_symbol: Symbol of the atom.</span>
<span class="sd">            ce_symbol: Symbol of the coordination environment.</span>

<span class="sd">        Returns:</span>
<span class="sd">            True if the coordination environment is found, False otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">isite</span><span class="p">,</span> <span class="n">site</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">):</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">Element</span><span class="p">(</span><span class="n">atom_symbol</span><span class="p">)</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="o">.</span>
                    <span class="n">element_composition</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_contains_environment</span><span class="p">(</span><span class="n">isite</span><span class="p">,</span> <span class="n">ce_symbol</span><span class="p">)):</span>
                <span class="k">return</span> <span class="kc">True</span>
        <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.environments_identified"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.environments_identified">[docs]</a>    <span class="k">def</span> <span class="nf">environments_identified</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the set of environments identified in this structure.</span>

<span class="sd">        Returns: Set of environments identified in this structure.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">set</span><span class="p">(</span><span class="n">ce</span><span class="p">[</span><span class="s1">&#39;ce_symbol&#39;</span><span class="p">]</span>
                   <span class="k">for</span> <span class="n">celist</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span> <span class="k">if</span> <span class="n">celist</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                   <span class="k">for</span> <span class="n">ce</span> <span class="ow">in</span> <span class="n">celist</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">uniquely_determines_coordination_environments</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        True if the coordination environments are uniquely determined.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">strategy</span><span class="o">.</span><span class="n">uniquely_determines_coordination_environments</span>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Equality method that checks if the LightStructureEnvironments object is equal to another</span>
<span class="sd">        LightStructureEnvironments object. Two LightStructureEnvironments objects are equal if the strategy used</span>
<span class="sd">        is the same, if the structure is the same, if the valences used in the strategies are the same, if the</span>
<span class="sd">        coordination environments and the neighbours determined by the strategy are the same.</span>

<span class="sd">        Args:</span>
<span class="sd">            other: LightStructureEnvironments object to compare with.</span>

<span class="sd">        Returns:</span>
<span class="sd">            True if both objects are equal, False otherwise.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">is_equal</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">strategy</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">strategy</span> <span class="ow">and</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">structure</span> <span class="ow">and</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">coordination_environments</span> <span class="ow">and</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">valences</span> <span class="ow">and</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">)</span>
        <span class="n">this_sites</span> <span class="o">=</span> <span class="p">[</span><span class="n">ss</span><span class="p">[</span><span class="s1">&#39;site&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">ss</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_all_nbs_sites</span><span class="p">]</span>
        <span class="n">other_sites</span> <span class="o">=</span> <span class="p">[</span><span class="n">ss</span><span class="p">[</span><span class="s1">&#39;site&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">ss</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">_all_nbs_sites</span><span class="p">]</span>
        <span class="n">this_indices</span> <span class="o">=</span> <span class="p">[</span><span class="n">ss</span><span class="p">[</span><span class="s1">&#39;index&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">ss</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_all_nbs_sites</span><span class="p">]</span>
        <span class="n">other_indices</span> <span class="o">=</span> <span class="p">[</span><span class="n">ss</span><span class="p">[</span><span class="s1">&#39;index&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">ss</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">_all_nbs_sites</span><span class="p">]</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">is_equal</span> <span class="ow">and</span> <span class="n">this_sites</span> <span class="o">==</span> <span class="n">other_sites</span> <span class="ow">and</span> <span class="n">this_indices</span> <span class="o">==</span> <span class="n">other_indices</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span> <span class="o">==</span> <span class="n">other</span>

<div class="viewcode-block" id="LightStructureEnvironments.as_dict"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Bson-serializable dict representation of the LightStructureEnvironments object.</span>
<span class="sd">        Returns:</span>
<span class="sd">            Bson-serializable dict representation of the LightStructureEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
                <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                <span class="s2">&quot;strategy&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">strategy</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                <span class="s2">&quot;structure&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                <span class="s2">&quot;coordination_environments&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_environments</span><span class="p">,</span>
                <span class="s2">&quot;all_nbs_sites&quot;</span><span class="p">:</span> <span class="p">[{</span><span class="s1">&#39;site&#39;</span><span class="p">:</span> <span class="n">nb_site</span><span class="p">[</span><span class="s1">&#39;site&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                                   <span class="s1">&#39;index&#39;</span><span class="p">:</span> <span class="n">nb_site</span><span class="p">[</span><span class="s1">&#39;index&#39;</span><span class="p">],</span>
                                   <span class="s1">&#39;image_cell&#39;</span><span class="p">:</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">ii</span><span class="p">)</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">nb_site</span><span class="p">[</span><span class="s1">&#39;image_cell&#39;</span><span class="p">]]}</span>
                                  <span class="k">for</span> <span class="n">nb_site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_all_nbs_sites</span><span class="p">],</span>
                <span class="s2">&quot;neighbors_sets&quot;</span><span class="p">:</span> <span class="p">[[</span><span class="n">nb_set</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">for</span> <span class="n">nb_set</span> <span class="ow">in</span> <span class="n">site_nb_sets</span><span class="p">]</span> <span class="k">if</span> <span class="n">site_nb_sets</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
                                   <span class="k">for</span> <span class="n">site_nb_sets</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">],</span>
                <span class="s2">&quot;valences&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span><span class="p">}</span></div>

<div class="viewcode-block" id="LightStructureEnvironments.from_dict"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.LightStructureEnvironments.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reconstructs the LightStructureEnvironments object from a dict representation of the</span>
<span class="sd">        LightStructureEnvironments created using the as_dict method.</span>

<span class="sd">        Args:</span>
<span class="sd">            d: dict representation of the LightStructureEnvironments object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            LightStructureEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">dec</span> <span class="o">=</span> <span class="n">MontyDecoder</span><span class="p">()</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">])</span>
        <span class="n">all_nbs_sites</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">nb_site</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;all_nbs_sites&#39;</span><span class="p">]:</span>
            <span class="n">site</span> <span class="o">=</span> <span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">nb_site</span><span class="p">[</span><span class="s1">&#39;site&#39;</span><span class="p">])</span>
            <span class="k">if</span> <span class="s1">&#39;image_cell&#39;</span> <span class="ow">in</span> <span class="n">nb_site</span><span class="p">:</span>
                <span class="n">image_cell</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">nb_site</span><span class="p">[</span><span class="s1">&#39;image_cell&#39;</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">diff</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span> <span class="o">-</span> <span class="n">structure</span><span class="p">[</span><span class="n">nb_site</span><span class="p">[</span><span class="s1">&#39;index&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">frac_coords</span>
                <span class="n">rounddiff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">diff</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="n">rounddiff</span><span class="p">):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Weird, differences between one site in a periodic image cell is not &#39;</span>
                                     <span class="s1">&#39;integer ...&#39;</span><span class="p">)</span>
                <span class="n">image_cell</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">rounddiff</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
            <span class="n">all_nbs_sites</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;site&#39;</span><span class="p">:</span> <span class="n">site</span><span class="p">,</span>
                                  <span class="s1">&#39;index&#39;</span><span class="p">:</span> <span class="n">nb_site</span><span class="p">[</span><span class="s1">&#39;index&#39;</span><span class="p">],</span>
                                  <span class="s1">&#39;image_cell&#39;</span><span class="p">:</span> <span class="n">image_cell</span><span class="p">})</span>
        <span class="n">neighbors_sets</span> <span class="o">=</span> <span class="p">[[</span><span class="bp">cls</span><span class="o">.</span><span class="n">NeighborsSet</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">dd</span><span class="o">=</span><span class="n">nb_set</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span>
                                                      <span class="n">all_nbs_sites</span><span class="o">=</span><span class="n">all_nbs_sites</span><span class="p">)</span>
                           <span class="k">for</span> <span class="n">nb_set</span> <span class="ow">in</span> <span class="n">site_nb_sets</span><span class="p">]</span> <span class="k">if</span> <span class="n">site_nb_sets</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
                          <span class="k">for</span> <span class="n">site_nb_sets</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;neighbors_sets&#39;</span><span class="p">]]</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">strategy</span><span class="o">=</span><span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;strategy&#39;</span><span class="p">]),</span>
                   <span class="n">coordination_environments</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;coordination_environments&#39;</span><span class="p">],</span>
                   <span class="n">all_nbs_sites</span><span class="o">=</span><span class="n">all_nbs_sites</span><span class="p">,</span>
                   <span class="n">neighbors_sets</span><span class="o">=</span><span class="n">neighbors_sets</span><span class="p">,</span>
                   <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span>
                   <span class="n">valences</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;valences&#39;</span><span class="p">])</span></div></div>


<div class="viewcode-block" id="ChemicalEnvironments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.ChemicalEnvironments">[docs]</a><span class="k">class</span> <span class="nc">ChemicalEnvironments</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class used to store all the information about the chemical environment of a given site for a given list of</span>
<span class="sd">    coordinated neighbours (internally called &quot;cn_map&quot;).</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coord_geoms</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initializes the ChemicalEnvironments object containing all the information about the chemical</span>
<span class="sd">        environment of a given site.</span>

<span class="sd">        Args:</span>
<span class="sd">            coord_geoms: coordination geometries to be added to the chemical environment.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">coord_geoms</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;Constructor for ChemicalEnvironments with the coord_geoms argument is not&#39;</span>
                                      <span class="s1">&#39;yet implemented&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mp_symbol</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the number of coordination geometries in this ChemicalEnvironments object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Number of coordination geometries in this ChemicalEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">cg</span><span class="p">,</span> <span class="n">cg_dict</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">yield</span> <span class="p">(</span><span class="n">cg</span><span class="p">,</span> <span class="n">cg_dict</span><span class="p">)</span>

<div class="viewcode-block" id="ChemicalEnvironments.minimum_geometry"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.ChemicalEnvironments.minimum_geometry">[docs]</a>    <span class="k">def</span> <span class="nf">minimum_geometry</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symmetry_measure_type</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">max_csm</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the geometry with the minimum continuous symmetry measure of this ChemicalEnvironments.</span>

<span class="sd">        Returns:</span>
<span class="sd">            tuple (symbol, csm) with symbol being the geometry with the minimum continuous symmetry measure and</span>
<span class="sd">            csm being the continuous symmetry measure associated to it.</span>

<span class="sd">        Raises:</span>
<span class="sd">            ValueError if no coordination geometry is found in this ChemicalEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="n">cglist</span> <span class="o">=</span> <span class="p">[</span><span class="n">cg</span> <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">symmetry_measure_type</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">csms</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">][</span><span class="s1">&#39;csm_wcs_ctwcc&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="n">cglist</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">csms</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">][</span><span class="n">symmetry_measure_type</span><span class="p">]</span> <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="n">cglist</span><span class="p">])</span>
        <span class="n">csmlist</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">cg</span><span class="p">]</span> <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="n">cglist</span><span class="p">]</span>
        <span class="n">imin</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">csms</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">max_csm</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">csmlist</span><span class="p">[</span><span class="n">imin</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">max_csm</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">None</span>
        <span class="k">return</span> <span class="n">cglist</span><span class="p">[</span><span class="n">imin</span><span class="p">],</span> <span class="n">csmlist</span><span class="p">[</span><span class="n">imin</span><span class="p">]</span></div>

<div class="viewcode-block" id="ChemicalEnvironments.minimum_geometries"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.ChemicalEnvironments.minimum_geometries">[docs]</a>    <span class="k">def</span> <span class="nf">minimum_geometries</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">symmetry_measure_type</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">max_csm</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a list of geometries with increasing continuous symmetry measure in this ChemicalEnvironments object.</span>

<span class="sd">        Args:</span>
<span class="sd">            n: Number of geometries to be included in the list.</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of geometries with increasing continuous symmetry measure in this ChemicalEnvironments object.</span>

<span class="sd">        Raises:</span>
<span class="sd">            ValueError if no coordination geometry is found in this ChemicalEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cglist</span> <span class="o">=</span> <span class="p">[</span><span class="n">cg</span> <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">symmetry_measure_type</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">csms</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">][</span><span class="s1">&#39;csm_wcs_ctwcc&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="n">cglist</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">csms</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">][</span><span class="n">symmetry_measure_type</span><span class="p">]</span> <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="n">cglist</span><span class="p">])</span>
        <span class="n">csmlist</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">cg</span><span class="p">]</span> <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="n">cglist</span><span class="p">]</span>
        <span class="n">isorted</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argsort</span><span class="p">(</span><span class="n">csms</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">max_csm</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">return</span> <span class="p">[(</span><span class="n">cglist</span><span class="p">[</span><span class="n">ii</span><span class="p">],</span> <span class="n">csmlist</span><span class="p">[</span><span class="n">ii</span><span class="p">])</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">isorted</span> <span class="k">if</span> <span class="n">csms</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">max_csm</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="p">[(</span><span class="n">cglist</span><span class="p">[</span><span class="n">ii</span><span class="p">],</span> <span class="n">csmlist</span><span class="p">[</span><span class="n">ii</span><span class="p">])</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">isorted</span><span class="p">[:</span><span class="n">n</span><span class="p">]</span> <span class="k">if</span> <span class="n">csms</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">max_csm</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">return</span> <span class="p">[(</span><span class="n">cglist</span><span class="p">[</span><span class="n">ii</span><span class="p">],</span> <span class="n">csmlist</span><span class="p">[</span><span class="n">ii</span><span class="p">])</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">isorted</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="p">[(</span><span class="n">cglist</span><span class="p">[</span><span class="n">ii</span><span class="p">],</span> <span class="n">csmlist</span><span class="p">[</span><span class="n">ii</span><span class="p">])</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">isorted</span><span class="p">[:</span><span class="n">n</span><span class="p">]]</span></div>

<div class="viewcode-block" id="ChemicalEnvironments.add_coord_geom"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.ChemicalEnvironments.add_coord_geom">[docs]</a>    <span class="k">def</span> <span class="nf">add_coord_geom</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mp_symbol</span><span class="p">,</span> <span class="n">symmetry_measure</span><span class="p">,</span> <span class="n">algo</span><span class="o">=</span><span class="s1">&#39;UNKNOWN&#39;</span><span class="p">,</span> <span class="n">permutation</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">override</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                       <span class="n">local2perfect_map</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">perfect2local_map</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">detailed_voronoi_index</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                       <span class="n">other_symmetry_measures</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">rotation_matrix</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">scaling_factor</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds a coordination geometry to the ChemicalEnvironments object.</span>

<span class="sd">        Args:</span>
<span class="sd">            mp_symbol: Symbol of the coordination geometry added.</span>
<span class="sd">            symmetry_measure: Symmetry measure of the coordination geometry added.</span>
<span class="sd">            algo: Algorithm used for the search of the coordination geometry added.</span>
<span class="sd">            permutation: Permutation of the neighbors that leads to the csm stored.</span>
<span class="sd">            override: If set to True, the coordination geometry will override the existent one if present.</span>
<span class="sd">            local2perfect_map: Mapping of the local indices to the perfect indices.</span>
<span class="sd">            perfect2local_map: Mapping of the perfect indices to the local indices.</span>
<span class="sd">            detailed_voronoi_index: Index in the voronoi containing the neighbors set.</span>
<span class="sd">            other_symmetry_measures: Other symmetry measure of the coordination geometry added (with/without the</span>
<span class="sd">                central atom, centered on the central atom or on the centroid with/without the central atom).</span>
<span class="sd">            rotation_matrix: Rotation matrix mapping the local geometry to the perfect geometry.</span>
<span class="sd">            scaling_factor: Scaling factor mapping the local geometry to the perfect geometry.</span>

<span class="sd">        Raises:</span>
<span class="sd">            ChemenvError if the coordination geometry is already added and override is set to False</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">allcg</span><span class="o">.</span><span class="n">is_a_valid_coordination_geometry</span><span class="p">(</span><span class="n">mp_symbol</span><span class="o">=</span><span class="n">mp_symbol</span><span class="p">):</span>
            <span class="k">raise</span> <span class="n">ChemenvError</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">,</span>
                               <span class="s1">&#39;add_coord_geom&#39;</span><span class="p">,</span>
                               <span class="s1">&#39;Coordination geometry with mp_symbol &quot;</span><span class="si">{mp}</span><span class="s1">&quot; is not valid&#39;</span>
                               <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mp</span><span class="o">=</span><span class="n">mp_symbol</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">mp_symbol</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">override</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">ChemenvError</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">,</span>
                               <span class="s2">&quot;add_coord_geom&quot;</span><span class="p">,</span>
                               <span class="s2">&quot;This coordination geometry is already present and override is set to False&quot;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">symmetry_measure</span><span class="p">),</span> <span class="s1">&#39;algo&#39;</span><span class="p">:</span> <span class="n">algo</span><span class="p">,</span>
                                           <span class="s1">&#39;permutation&#39;</span><span class="p">:</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">permutation</span><span class="p">],</span>
                                           <span class="s1">&#39;local2perfect_map&#39;</span><span class="p">:</span> <span class="n">local2perfect_map</span><span class="p">,</span>
                                           <span class="s1">&#39;perfect2local_map&#39;</span><span class="p">:</span> <span class="n">perfect2local_map</span><span class="p">,</span>
                                           <span class="s1">&#39;detailed_voronoi_index&#39;</span><span class="p">:</span> <span class="n">detailed_voronoi_index</span><span class="p">,</span>
                                           <span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">:</span> <span class="n">other_symmetry_measures</span><span class="p">,</span>
                                           <span class="s1">&#39;rotation_matrix&#39;</span><span class="p">:</span> <span class="n">rotation_matrix</span><span class="p">,</span>
                                           <span class="s1">&#39;scaling_factor&#39;</span><span class="p">:</span> <span class="n">scaling_factor</span><span class="p">}</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a string representation of the ChemicalEnvironments object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            String representation of the ChemicalEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">out</span> <span class="o">=</span> <span class="s1">&#39;Chemical environments object :</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39; =&gt; No coordination in it &lt;=</span><span class="se">\n</span><span class="s1">&#39;</span>
            <span class="k">return</span> <span class="n">out</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">mp_symbol</span> <span class="o">=</span> <span class="n">key</span>
            <span class="k">break</span>
        <span class="n">cn</span> <span class="o">=</span> <span class="n">symbol_cn_mapping</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">]</span>
        <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39; =&gt; Coordination </span><span class="si">{}</span><span class="s1"> &lt;=</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cn</span><span class="p">)</span>
        <span class="n">mp_symbols</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
        <span class="n">csms_wcs</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">][</span><span class="s1">&#39;csm_wcs_ctwcc&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">mp_symbol</span> <span class="ow">in</span> <span class="n">mp_symbols</span><span class="p">]</span>
        <span class="n">icsms_sorted</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argsort</span><span class="p">(</span><span class="n">csms_wcs</span><span class="p">)</span>
        <span class="n">mp_symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">mp_symbols</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">icsms_sorted</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">mp_symbol</span> <span class="ow">in</span> <span class="n">mp_symbols</span><span class="p">:</span>
            <span class="n">csm_wcs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">][</span><span class="s1">&#39;csm_wcs_ctwcc&#39;</span><span class="p">]</span>
            <span class="n">csm_wocs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">][</span><span class="s1">&#39;csm_wocs_ctwocc&#39;</span><span class="p">]</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39;   - </span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mp_symbol</span><span class="p">)</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39;      csm1 (with central site) : </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">csm_wcs</span><span class="p">)</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39;      csm2 (without central site) : </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">csm_wocs</span><span class="p">)</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39;     algo : </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;algo&#39;</span><span class="p">])</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39;     perm : </span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;permutation&#39;</span><span class="p">])</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39;       local2perfect : </span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;local2perfect_map&#39;</span><span class="p">]))</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39;       perfect2local : </span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;perfect2local_map&#39;</span><span class="p">]))</span>
        <span class="k">return</span> <span class="n">out</span>

<div class="viewcode-block" id="ChemicalEnvironments.is_close_to"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.ChemicalEnvironments.is_close_to">[docs]</a>    <span class="k">def</span> <span class="nf">is_close_to</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="n">rtol</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">atol</span><span class="o">=</span><span class="mf">1e-8</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Whether this ChemicalEnvironments object is close to another one.</span>

<span class="sd">        Args:</span>
<span class="sd">            other: Another ChemicalEnvironments object.</span>
<span class="sd">            rtol: Relative tolerance for the comparison of Continuous Symmetry Measures.</span>
<span class="sd">            atol: Absolute tolerance for the comparison of Continuous Symmetry Measures.</span>

<span class="sd">        Returns:</span>
<span class="sd">            True if the two ChemicalEnvironments objects are close to each other.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span> <span class="o">!=</span> <span class="nb">set</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">coord_geoms</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">for</span> <span class="n">mp_symbol</span><span class="p">,</span> <span class="n">cg_dict_self</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">cg_dict_other</span> <span class="o">=</span> <span class="n">other</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">]</span>
            <span class="n">other_csms_self</span> <span class="o">=</span> <span class="n">cg_dict_self</span><span class="p">[</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">]</span>
            <span class="n">other_csms_other</span> <span class="o">=</span> <span class="n">cg_dict_other</span><span class="p">[</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">]</span>
            <span class="k">for</span> <span class="n">csmtype</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;csm_wcs_ctwcc&#39;</span><span class="p">,</span> <span class="s1">&#39;csm_wcs_ctwocc&#39;</span><span class="p">,</span> <span class="s1">&#39;csm_wcs_csc&#39;</span><span class="p">,</span>
                            <span class="s1">&#39;csm_wocs_ctwcc&#39;</span><span class="p">,</span> <span class="s1">&#39;csm_wocs_ctwocc&#39;</span><span class="p">,</span> <span class="s1">&#39;csm_wocs_csc&#39;</span><span class="p">]:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">other_csms_self</span><span class="p">[</span><span class="n">csmtype</span><span class="p">],</span> <span class="n">other_csms_other</span><span class="p">[</span><span class="n">csmtype</span><span class="p">],</span> <span class="n">rtol</span><span class="o">=</span><span class="n">rtol</span><span class="p">,</span> <span class="n">atol</span><span class="o">=</span><span class="n">atol</span><span class="p">):</span>
                    <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="kc">True</span></div>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Equality method that checks if the ChemicalEnvironments object is equal to another ChemicalEnvironments.</span>
<span class="sd">        object.</span>

<span class="sd">        Args:</span>
<span class="sd">            other: ChemicalEnvironments object to compare with.</span>

<span class="sd">        Returns:</span>
<span class="sd">            True if both objects are equal, False otherwise.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span> <span class="o">!=</span> <span class="nb">set</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">coord_geoms</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">for</span> <span class="n">mp_symbol</span><span class="p">,</span> <span class="n">cg_dict_self</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">cg_dict_other</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">[</span><span class="n">mp_symbol</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">cg_dict_self</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="n">cg_dict_other</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]:</span>
                <span class="k">return</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="n">cg_dict_self</span><span class="p">[</span><span class="s1">&#39;algo&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="n">cg_dict_other</span><span class="p">[</span><span class="s1">&#39;algo&#39;</span><span class="p">]:</span>
                <span class="k">return</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="n">cg_dict_self</span><span class="p">[</span><span class="s1">&#39;permutation&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="n">cg_dict_other</span><span class="p">[</span><span class="s1">&#39;permutation&#39;</span><span class="p">]:</span>
                <span class="k">return</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="n">cg_dict_self</span><span class="p">[</span><span class="s1">&#39;detailed_voronoi_index&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="n">cg_dict_other</span><span class="p">[</span><span class="s1">&#39;detailed_voronoi_index&#39;</span><span class="p">]:</span>
                <span class="k">return</span> <span class="kc">False</span>
            <span class="n">other_csms_self</span> <span class="o">=</span> <span class="n">cg_dict_self</span><span class="p">[</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">]</span>
            <span class="n">other_csms_other</span> <span class="o">=</span> <span class="n">cg_dict_other</span><span class="p">[</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">]</span>
            <span class="k">for</span> <span class="n">csmtype</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;csm_wcs_ctwcc&#39;</span><span class="p">,</span> <span class="s1">&#39;csm_wcs_ctwocc&#39;</span><span class="p">,</span> <span class="s1">&#39;csm_wcs_csc&#39;</span><span class="p">,</span>
                            <span class="s1">&#39;csm_wocs_ctwcc&#39;</span><span class="p">,</span> <span class="s1">&#39;csm_wocs_ctwocc&#39;</span><span class="p">,</span> <span class="s1">&#39;csm_wocs_csc&#39;</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">other_csms_self</span><span class="p">[</span><span class="n">csmtype</span><span class="p">]</span> <span class="o">!=</span> <span class="n">other_csms_other</span><span class="p">[</span><span class="n">csmtype</span><span class="p">]:</span>
                    <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="kc">True</span>

    <span class="k">def</span> <span class="fm">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span> <span class="o">==</span> <span class="n">other</span>

<div class="viewcode-block" id="ChemicalEnvironments.as_dict"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.ChemicalEnvironments.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a dictionary representation of the ChemicalEnvironments object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A dictionary representation of the ChemicalEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
                <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                <span class="s2">&quot;coord_geoms&quot;</span><span class="p">:</span> <span class="n">jsanitize</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_geoms</span><span class="p">)}</span></div>

<div class="viewcode-block" id="ChemicalEnvironments.from_dict"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.structure_environments.html#pymatgen.analysis.chemenv.coordination_environments.structure_environments.ChemicalEnvironments.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reconstructs the ChemicalEnvironments object from a dict representation of the ChemicalEnvironments created</span>
<span class="sd">        using the as_dict method.</span>

<span class="sd">        Args:</span>
<span class="sd">            d: dict representation of the ChemicalEnvironments object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            ChemicalEnvironments object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ce</span> <span class="o">=</span> <span class="bp">cls</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;local2perfect_map&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">l2p_map</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">l2p_map</span> <span class="o">=</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">key</span><span class="p">):</span> <span class="nb">int</span><span class="p">(</span><span class="n">val</span><span class="p">)</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;local2perfect_map&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="k">if</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;perfect2local_map&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">p2l_map</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">p2l_map</span> <span class="o">=</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">key</span><span class="p">):</span> <span class="nb">int</span><span class="p">(</span><span class="n">val</span><span class="p">)</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;perfect2local_map&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="k">if</span> <span class="p">(</span><span class="s1">&#39;other_symmetry_measures&#39;</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">]</span> <span class="ow">and</span>
                    <span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">):</span>
                <span class="n">other_csms</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;other_symmetry_measures&#39;</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">other_csms</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">ce</span><span class="o">.</span><span class="n">add_coord_geom</span><span class="p">(</span><span class="n">cg</span><span class="p">,</span>
                              <span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">],</span>
                              <span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;algo&#39;</span><span class="p">],</span>
                              <span class="n">permutation</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;permutation&#39;</span><span class="p">],</span>
                              <span class="n">local2perfect_map</span><span class="o">=</span><span class="n">l2p_map</span><span class="p">,</span>
                              <span class="n">perfect2local_map</span><span class="o">=</span><span class="n">p2l_map</span><span class="p">,</span>
                              <span class="n">detailed_voronoi_index</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;detailed_voronoi_index&#39;</span><span class="p">],</span>
                              <span class="n">other_symmetry_measures</span><span class="o">=</span><span class="n">other_csms</span><span class="p">,</span>
                              <span class="n">rotation_matrix</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;rotation_matrix&#39;</span><span class="p">],</span>
                              <span class="n">scaling_factor</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;coord_geoms&#39;</span><span class="p">][</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;scaling_factor&#39;</span><span class="p">])</span>
        <span class="k">return</span> <span class="n">ce</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.chemenv.coordination_environments.structure_environments</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>